Php – Optimizing fastcgi + php5

fastcgilighttpdPHPxcache

Running a debian system with lighttpd, php5, xcache and fastcgi. 2GB ram, 2 cores, less than 10% cpu load in 5 min averages peak time, less than 1GB of ram in use.

The system runs a custom build webapp that scrapes flight search sites, no caching (of results) allowed so it's made in real time, and the code that does it uses libcurl and can probably be executed for quite a few seconds for every search. There's also an OpenX ad system.

Recently the site seem to timeout intermittently, and I have create a simple test script that just prints a word to make sure it's not related to the MySQL database.

From what I understand, as we run an opcode cacher we should not run many fastcgi "max-procs" (because each process would use it's own cache, I assume), but instead increase the children.
The childs was increased from 20 (with 2 max-procs) to 32, with no noticable difference.
From what I understand, the amount of simultaneous scripts that runs are max-procs * children. Looking at the output of status.statistics-url while scripts take ages to run doesnt seem to indicate that all children are busy.

Is the correct approach to keep increasing children of fastcgi, or what more is there to do?
Is it possible to see which scripts are in runtime, for how long they run etc etc etc?

fastcgi.active-requests: 39
fastcgi.backend.0.0.connected: 2259
fastcgi.backend.0.0.died: 0
fastcgi.backend.0.0.disabled: 0
fastcgi.backend.0.0.load: 19
fastcgi.backend.0.0.overloaded: 0
fastcgi.backend.0.1.connected: 4646
fastcgi.backend.0.1.died: 0
fastcgi.backend.0.1.disabled: 0
fastcgi.backend.0.1.load: 20
fastcgi.backend.0.1.overloaded: 0
fastcgi.backend.0.load: 39
fastcgi.requests: 6905

10-fastcgi.conf:
"max-procs" => 2,
"idle-timeout" => 20,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "32",
"PHP_FCGI_MAX_REQUESTS" => "500"

lighttpd error log, loads of these:
2011-05-30 09:45:48: (server.c.1258) NOTE: a request for /index.php?//search/poll timed out after writing 15180 bytes. We waited 360 seconds. If this a problem increase server.max-write-idle
2011-05-30 09:49:08: (server.c.1258) NOTE: a request for /index.php?// timed out after writing 12420 bytes. We waited 360 seconds. If this a problem increase server.max-write-idle

Best Answer

Change your PHP binary to FPM instead of old fastcgi.

FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features (mostly) useful for heavy-loaded sites.

Works much more stable, you shouldn't have timeout problems with it.