Sunday, August 3, 2008
Sphinx - Free open-source SQL full-text search engineBookmarked on del.icio.us at 10:31.
Tags: cache, database, db, geek, programming, software, sphinx, sql
Monday, July 14, 2008
php-fpm: a smoother PHP/FastCGI process managerScribbled to Igor’s scrawls at 23:49
Tags: nginx php php-fpm load linux patch geek code
I’ve been running PHP apps with the standard PHP FastCGI server behind nginx for a couple of years now, and in that time have worked up a set of tools to manage PHP processes with multiple configuration profiles. This has been based around my slightly hacked version of Alexey Kovyrin’s PHP–FCGI spawn script, along with a chkconfig–compatible init script I’ve written as a front–end to control it, taking in some simple per–profile configuration in /etc/sysconfig/php-fcgi.
Various contributors to the English nginx mailing list have posted in that time singing the praises of Andrei Nigmatulin’s php-fpm, a patch to the PHP source which adds “FastCGI Process Management” to the standard php-fcgi binary. It’s apparently in use in some pretty heavily–loaded sites, and I’ve had it in mind to check it out, but as my setup has been stable (if not exactly full–featured) over the last few projects, I haven’t had a huge impetus to get and do it. Today, however, I finally had enough downtime to check it out, and now I’m wishing I’d done it earlier.
My existing method basically worked like this:
· init script reads configuration file, with one “profile” per line detailing location of php.ini file, interface and port to run on, number of child processes to run, number of requests to serve before a re–spawn, etc.;
· init script uses these details to construct a command–line to call Alexey’s spawn script, once for each profile;
· spawn script constructs environment and command–line argument list to spawn a set of PHP processes for each profile entry.
This has worked fine, but as so often with these things, the init script became a bit unwieldy with additions over time, and is still unable to do anything elegant like graceful restarts on the PHP daemons.
php-fpm addresses these issues and more. The “profile” configuration is put into a sensible, clear configuration file (php-fpm.conf) which allows you to specify a number of named PHP process “pools”, each with its own detailed FastCGI server and PHP configuration.
The documentation’s somewhat light, and mostly in Russian, but it has all you need to get going, and the configuration file is easy to read. Once you’ve configured the pools you want (in my case sets of named dev/stage/live setups on different ports, so as to keep include_paths — and therefore library code — properly staged), you just need to run php-cgi --fpm. From there on, you can send various signals to the master process including SIGQUIT for a graceful stop, SIGUSR1 to cycle log files, and SIGUSR2 for a graceful reload/restart. The master process ID is stored in $PHP_PREFIX/logs/php-fpm.pid.
I’ll probably write a simple chkconfig/init wrapper to send these signals to the master using e.g. /etc/init.d/php-fpm graceful, but that’s about all I’ll need to do in order to replicate and extend my existing setup.
Not only does this simplify and tidy up my PHP–FCGI setup enormously, it also adds a number of convenient extra points, including IP–restriction and a nice fix for the “empty error” page problem. Intuitively it “feels” a lot more solid, and I’m looking forward to trying it out on the next suitable project. Nice bit of Russian coder humour there on the “extra points” page, too. Thanks, Andrei!
Wednesday, November 21, 2007
xajax PHP Class Library - The easiest way to develop asynchronous Ajax applications with PHPBookmarked on del.icio.us at 12:05.
Tags: code, geek
Tuesday, November 13, 2007
Lumine - Database Mapping For PHPBookmarked on del.icio.us at 23:07.
Tags: db
Thursday, October 11, 2007
Multiuser Apache+PHP+mod_fastcgi setupBookmarked on del.icio.us at 20:18.
Tags: admin, apache, config, geek, unix
Wednesday, June 27, 2007
Mac OS X launchd plist to run PHP fcgiBookmarked on del.icio.us at 13:38.
Tags: fcgi, php
Tuesday, June 12, 2007
Template EnginesBookmarked on del.icio.us at 15:55.
Tags: code, geek, templates
Wednesday, April 11, 2007
International PHP Mag: "OO approach for shared memory"Bookmarked on del.icio.us at 15:24.
Tags: php, shmem
