Introduction to php-fpm (PHP-FPM is a PHPFastCGI manager)
PHP-FPM is actually a patch of PHP source code, designed to integrate FastCGI process management into the PHP package. You must patch it to your PHP source code before using it after compiling and installing PHP.
Now we can download the source code tree in the latest PHP 5.3.2 to directly integrate the branch of the PHP-FPM, it is said that the next version will be integrated into the main branch of PHP. Compared with Spawn-FCGI, PHP-FPM has better control over CPU and memory, and the former is easy to crash and must be monitored with crontab, while PHP-FPM has no such troubles.
PHP5.3.3 has already integrated php-fpm and is no longer a third-party package. PHP-FPM provides a better PHP process management method, can effectively control the memory and process, can smoothly load PHP configuration, than spawn-fcgi has more advantages, so it is officially included by PHP. ? The enable-fpm parameter enables PHP-FPM.
Use PHP-FPM to control FastCGI processes of PHP-CGI
/Usr/local/php/sbin/php-fpm {start | stop | quit | restart | reload | logrotate}
-- Start the fastcgi process of php
-- Stop force terminate the fastcgi process of php
-- Quit: smoothly terminate the fastcgi process of php
-- Restart the fastcgi process of php
-- Reload re-smoothly loads php. ini
-- Logrotate re-enable log files
Special features
All these features are implemented in a "do not interrupt" manner. That is to say, if you do not use them, their existence will not affect the functionality of php ?? They are all "transparent.
Error header
Scope: php. ini options
Category: convenience
By default, if the Accessed php script contains a syntax error, the user will receive an empty "200 OK" page. This is inconvenient. Error header: php. the ini option allows an HTTP error code, such as "HTTP/1.0 550 Server Made Big Boo", to interrupt the web server request and display a correct error page.
To implement this function, add fastcgi. error_header = "HTTP/1.0 550 Server Made Big Boo" in php. ini"
Added similar but different features in the php-5.2.4: If the Accessed php script contains syntax errors and display_errors = off, "HTTP/1.0 500 Internal Server Error" is returned immediately ".
If you need to set a 503 error or want to make this behavior independent of display_errors, you can use fastcgi. error_header. If you enable php-fpm on a php-5.2.5 or a later version, fastcgi. error_header has a higher priority.
Optimized Upload support
ESSENCE: web server support
Type: Optimized
This feature, as the name suggests, can accelerate the processing of large POST requests, including file uploads. Optimization is implemented by writing the request body into a temporary file and passing the file name through the fastcgi protocol instead of the request body. As far as I know, nginx0.5.9 and later support this function. Obviously, this mode can be used only when php and web server are on one machine.
Nginx sample configuration:
Location ~ \. Php $ {
Fastcgi_pass_request_body off;
Client_body_in_file_only clean;
Fastcgi_param REQUEST_BODY_FILE $ request_body_file;
...
Fastcgi_pass ...;
}
You do not need to configure anything in php. If php receives the REQUEST_BODY_FILE parameter, it will read the request body. if not, it will read the request body from the fastcgi protocol.
With this feature, you can consider using a memory file system for temporary files, such as tmpfs (linux ):
Client_body_temp_path/dev/shm/client_body_temp;
Fastcgi_finish_request ()
Scope: php functions
Type: Optimized
This feature improves the processing speed of some php requests. If some processing can be performed after the page is generated, this optimization can be used. For example, you can save the session in memcached after the page is handed over to the web server. Fastcgi_finisth_request (), which can end the response output. the web server can immediately start to deliver the response to the client that cannot wait. at this moment, php can process many tasks in the request context. For example, save the session, convert the uploaded video, and process statistics.
Fastcgi_finisth_request () triggers the shutdown function.
Request_slowlog_timeout
Scope: php-fpm.conf options
Category: Convenient
This option allows you to track and execute slow scripts and record them together with the call stack to log files. For example:
5S
Logs/slow. log
As you can see in the example, the script runs for more than five seconds, probably because of the slow mysql response (top backtrace ).