Make php-fpm execute arbitrary PHP scripts via socket
We are using APC cache very heavily in our projects and during project deployment the cache must be flushed and warmed up. A common solution to warmup the APC cache is to fetch some special page via HTTP which does the job.
The problem with this approach is that it’s not reliable enough when PHP is served via several fastcgi back-ends. You may actually never know which back-end is going to serve your HTTP request. And I needed a solution which would warmup caches on every PHP back-end for sure.
For this reason I extracted some fastcgi related bits from the Nanoweb PHP web server and created a phpfpm module which allows to directly talk to the fastcgi via socket and execute arbitrary PHP scripts. Here’s the usage example:
<?php include("phpfpm.inc.php"); $filename = "/path/to/project/bin/apc_warmup.php"; $response = phpfpm_request("localhost", 9000, $filename); var_dump($response);
Note, it was tested only with php-fpm so I’m not sure if it’s going to work with anything else. The code of phpfpm.inc.php is quite “hackish” but, hey, it does its job

October 28th, 2011 at 8:33 pm
PHP Scripts…
[…]My desperate life quest for efficiency » Blog Archive » Make php-fpm execute arbitrary PHP scripts via socket[…]…
April 22nd, 2012 at 12:47 pm
What is the largest response you’ve got? I am hitting a hard limit of 8131 bytes, any idea why? The same file via Nginx returns fine.
April 22nd, 2012 at 12:54 pm
Sorry, no idea
I’ve never needed a response of such size… Well, you’ve got the source 
April 23rd, 2012 at 2:02 am
Fair enough, I’ll keep messing with it and let you know if I find anything. By the way, I’m connecting to php-fpm via a unix socket, host is unix:///path/to/socket.sock, port is 0 or NULL, it’s a tad faster if you care for that kind of thing.
April 23rd, 2012 at 11:53 am
Sure, thanks!