« Previous 1 2 3 4
The PHP FastCGI process manager, PHP-FPM
Substitute
Parallel Processing
PHP-FPM provides a new PHP function called fastcgi_finish_request(). As its name implies, fastcgi_finish_request() exits the request, but the script continues to run in the background. An example of a practical application for this technique is given in Listing 3; however, fastcgi_finish_request() only exists in PHP-FPM; other PHP interpreters will not run the script.
Listing 3
fastcgi_finish_request()
01 <?PHP
02 //...
03
04 if(!is_file('preview.png'))
05 {
06 echo "Creating a preview, please re-load after 10 seconds";
07 // Terminate request...
08 fastcgi_finish_request();
09 // ... but still continue processing this:
10 create_preview();
11 }
12 else show('preview.png');
13
14 //...
15
16 ?>
Conclusions
PHP-FPM enhances security and scales well, although its approach does not automatically accelerate delivery times, compared with the conventional FastCGI interpreter.
The impressive figures published on the Internet usually pertain to comparisons of Apache 2 with mod_php to the combination of a small and lean web server such as Nginx with PHP-FPM.
Nginx
In production use, many administrators combine PHP-FPM with the lean and fast Nginx web server. For the two to cooperate, you need the following lines in your Nginx configuration file:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
# ...
}If you are using sockets, replace the fastcgi_pass line with:
fastcgi_pass unix:/tmp/php5-fpm.socket
where /tmp/php5-fpm.socket is the socket name.
If you want to accelerate the response speed for your PHP-FPM configuration, it is important to carry out additional optimizations.
Infos
- FastCGI: http://www.fastcgi.com
- PHP-FPM: http://php-fpm.org/
- PHP-FPM in the PHP Manual: http://php.net/manual/en/install.fpm.php
- mod_fastcgi: http://www.fastcgi.com/dist/
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)