Posted by omega8cc on September 8, 2009 at 12:15am
Do you still use spawn-fcgi with Nginx? It's time to consider PHP-FPM.
PHP in the form in which it is available from php.net has a number of well-known issues associated with the use of the FastCGI SAPI in production. See this comparison chart of problems and how php-fpm handles them, when enabled with the FastCGI SAPI.
Features available only in PHP-FPM:
- Process Management. Ability to "graceful" stop and start php workers without losing any queries. The possibility of gradually update the configuration and binary without losing any queries.
- Emergency restart all the processes in the event of accidental destruction of shared memory opcode cache, if used accelerator.
- Starting the workers with different uid/gid/chroot/environment and different php.ini option. You do not need a safe mode!
- Forcing the completion of process if set_time_limit() fails
- Logging stdout & stderr business processes.
PHP-FPM start/stop example: http://omega8.cc/dev/php-fpm-init-d.txt
Questions? Problems? Comments?
Let me know!
~Grace
Comments
Thanks for the writeup. I
Thanks for the writeup. I was also wondering what you think is good for PHP_FCGI_CHILDREN for a 360MB VPS and do you vary from the default for things like
## Size Limits
client_body_buffer_size 8k;
client_header_buffer_size 32k;
client_max_body_size 8k;
large_client_header_buffers 4 32k;
and
## Fastcgi
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 32k;
fastcgi_buffers 16 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_temp_file_write_size 64k;
fastcgi_intercept_errors on;
I'm not sure what the defaults are, but I know if I set some of the buffers too small it definitely causes problems.
I always recommend to start
I always recommend to start with default settings/values and tune it only if you experience any problems.
If you will raise some values, for example timeouts, you can feel you resolved the problem, but if you need to raise these limits it can be because there is something wrong, for example, with MySQL settings or not optimized SQL queries etc.
Furthermore, raising limits can lead to opening your system to DoS attacks.
Most of servers/sites I manage works fine with default
fastcgi_
settings, while for Nginx my own defaults looks similar to:## Size Limits
client_body_buffer_size 1k;
client_header_buffer_size 1k;
client_max_body_size 10m;
large_client_header_buffers 3 3k;
connection_pool_size 256;
request_pool_size 4k;
server_names_hash_bucket_size 128;
## Timeouts
client_body_timeout 60;
client_header_timeout 60;
keepalive_timeout 75 20;
send_timeout 60;
PHP_FCGI_CHILDREN for a 360MB VPS? For PHP-FPM 3-5 should be fine:
<value name="max_children">5</value>
~Grace
I updated the links, since
I updated the links, since this information is now available at http://legacy.php-fpm.org, because FPM is now moving to the PHP core and the live page is available at https://launchpad.net/php-fpm/
Antony Dovgal, one of core PHP developers has just made an
announcement that FPM (without PHP) has become an official PHP
project. Here is the full text of that announcement
---------------------------------------------------------
Hello all.
I'm glad to announce that we now have FPM SAPI available for testing
in a separate SVN branch.
The full announcement:
http://groups.google.com/group/highload-php-en/browse_thread/thread/f794...
How to install php-fpm with
How to install php-fpm with nginx on centos 5?
php-fpm with nginx on CentOS 5
I don't use CentOS, however I helped eranb22 to prepare working recipe for php-fpm build on CentOS 5.
He posted it here: http://forums.rimuhosting.com/forums/showthread.php?p=1361
HTH,
~Grace