Script to spawn php5-cgi to enable Nginx to serve PHP code/pages

Artis Caune artis.caune at gmail.com
Thu Nov 6 14:16:10 MSK 2008


2008/11/6 Volodymyr Kostyrko <c.kworr at gmail.com>:
> I use FreeBSD at large, but have composed a tiny snippet for some old CentOS
> server:

I like to spawn php processes like jail_* does:   :)

# /etc/rc.conf

phpfcgi_enable="YES"
phpfcgi_list="roundcube roundcube2"
#
phpfcgi_roundcube_pid="/home/www/roundcube/pid"
phpfcgi_roundcube_socket="/home/www/roundcube/fcgi"
phpfcgi_roundcube_children="64"
phpfcgi_roundcube_requests="1000
#
phpfcgi_roundcube2_pid="/home/www/roundcube2/pid"
phpfcgi_roundcube2_socket="127.0.0.1:8080"




# /usr/local/etc/rc.d/phpfcgi start
# /usr/local/etc/rc.d/phpfcgi restart roundcube
# /usr/local/etc/rc.d/phpfcgi stop roundcube2




# vim /usr/local/etc/rc.d/phpfcgi
#!/bin/sh

# PROVIDE: phpfcgi
# REQUIRE: DAEMON
# BEFORE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="phpfcgi"
rcvar=`set_rcvar`
start_cmd="phpfcgi_start"
stop_cmd="phpfcgi_stop"

init_variables()
{
    _f="$1"

    if [ -z "$_f" ]; then
        warn "init_variables: you must specify a phpfcgi"
        return
    fi

    eval _user=\"\$phpfcgi_${_f}_user\"
    eval _pid=\"\$phpfcgi_${_f}_pid\"
    eval _program=\"\$phpfcgi_${_f}_program\"
    eval _socket=\"\$phpfcgi_${_f}_socket\"
    eval _children=\"\$phpfcgi_${_f}_children\"
    eval _requests=\"\$phpfcgi_${_f}_requests\"

    [ -z "${_user}" ] && _user="www"
    [ -z "${_program}" ] && _program="/usr/local/bin/php-cgi"
    [ -z "${_children}" ] && _children="8"
    [ -z "${_requests}" ] && _requests="1000"

    if [ -z "${_pid}" ]; then
        err 3 "$name: No pid has been defined for ${_f}"
    fi
    if [ -z "${_socket}" ]; then
        err 3 "$name: No socket has been defined for ${_f}"
    fi
}

phpfcgi_start() {
    echo -n 'Starting phpfcgis: '
    for _phpfcgi in ${phpfcgi_list}; do
        init_variables $_phpfcgi
        echo -n "${_phpfcgi} "

        PHP_FCGI_CHILDREN=${_children} \
        PHP_FCGI_MAX_REQUESTS=${_requests} \
        /usr/sbin/daemon -u ${_user} -p ${_pid} ${_program} -b ${_socket}
    done
    echo '.'
}

phpfcgi_stop() {
    echo -n 'Stopping phpfcgis: '
    for _phpfcgi in ${phpfcgi_list}; do
        init_variables $_phpfcgi

        if [ -f ${_pid} ]; then
            echo -n "${_phpfcgi} "
            kill -TERM $(cat ${_pid}) && rm -f ${_pid}
        fi
    done
    echo '.'
}

load_rc_config $name
cmd="$1"
if [ $# -gt 0 ]; then
        shift
fi
if [ -n "$*" ]; then
        phpfcgi_list="$*"
fi
run_rc_command "${cmd}"






-- 
regards,
Artis Caune

<----. CCNA | BSDA
<----|====================
<----' didii FreeBSD





More information about the nginx mailing list