|
Lighttpd 1.4 on Unix systemsThis section contains notes and hints specific to Lighttpd 1.4 installs of PHP on Unix systems. Please use the » Lighttpd trac to learn how to install Lighttpd properly before continuing. FastCGI is the preferred SAPI to connect PHP and Lighttpd. FastCGI is automagically enabled in php-cgi. Letting Lighttpd spawn php processesTo configure Lighttpd to connect to PHP and spawn FastCGI processes, edit lighttpd.conf. Sockets are preferred to connect to FastCGI processes on the local system. Example #1 Partial lighttpd.conf
server.modules += ( "mod_fastcgi" )
fastcgi.server = ( ".php" =>
((
"socket" => "/tmp/php.socket",
"bin-path" => "/usr/local/bin/php-cgi",
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "16",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"min-procs" => 1,
"max-procs" => 1,
"idle-timeout" => 20
))
)
The bin-path directive allows lighttpd to spawn FastCGI processes dynamically.
PHP will spawn children according to the PHP_FCGI_CHILDREN environment
variable. The Spawning with spawn-fcgiLighttpd provides a program called spawn-fcgi to make the process of spawning FastCGI processes easier. Spawning php-cgiIt is possible to spawn processes without spawn-fcgi, though a bit of heavy-lifting is required. Setting the PHP_FCGI_CHILDREN environment var controls how many children PHP will spawn to handle incoming requests. Setting PHP_FCGI_MAX_REQUESTS will determine how long (in requests) each child will live. Here's a simple bash script to help spawn php responders. Example #2 Spawning FastCGI Responders
#!/bin/sh
# Location of the php-cgi binary
PHP=/usr/local/bin/php-cgi
# PID File location
PHP_PID=/tmp/php.pid
# Binding to an address
#FCGI_BIND_ADDRESS=10.0.1.1:10000
# Binding to a domain socket
FCGI_BIND_ADDRESS=/tmp/php.sock
PHP_FCGI_CHILDREN=16
PHP_FCGI_MAX_REQUESTS=10000
env -i PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN \
PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS \
$PHP -b $FCGI_BIND_ADDRESS &
echo $! > "$PHP_PID"
Connecting to remote FCGI instancesFastCGI instances can be spawned on multiple remote machines in order to scale applications. Example #3 Connecting to remote php-fastcgi instances
fastcgi.server = ( ".php" =>
(( "host" => "10.0.0.2", "port" => 1030 ),
( "host" => "10.0.0.3", "port" => 1030 ))
)
|