Features
From PHP-FPM
Contents |
Error Header
All these features are implemented in a manner that does "not break". That is, if you're not using them, their existence does not affect the functionality of php - all of which are "transparent."
Scope: php.ini option
Category: Convenience
By default, if they call php script contains a parse error, the user receives a blank "200 Ok" page. This is inconvenient. Error header - this php.ini option, which allows for such cases to issue arbitrary HTTP error code, for example, "HTTP/1.0 550 Server Made Big Boo", which can then be intercepted a Web server and display the correct error page.
To achieve this, please specify the following in your php.ini:
fastcgi.error_header = "HTTP/1.0 550 Server Made Big Boo"
php-5.2.4 added a similar, yet different functionality: if the executed php script contains a parse error and display_errors = off, PHP issues a "HTTP/1.0 500 Internal Server Error" right away.
If you want to issue a 503 error, or want to do achieve this behavior independent of display_errors, you will have to use fastcgi.error_header. If you are using php-5.2.4+ with php-fpm enabled, the fastcgi.error_header has priority.
Accelerated upload support
The essence: the support of the web server Category: Optimization
This feature, as the name implies, allows faster processing of large POST requests, including file uploads. Acceleration is achieved by ensuring that the body of the request is recorded into a temporary file and fastcgi protocol passes file path instead of the request body. At the moment, as far as I know, only nginx 0.5.9 + supports this functionality. Obviously, such a scheme will only work if php is a host with a Web server.
Sample nginx configuration:
location ~\.php$ {
fastcgi_pass_request_body off;
client_body_in_file_only clean;
fastcgi_param REQUEST_BODY_FILE $request_body_file;
...
fastcgi_pass ...;
}
In php you do not need to configure anything. If php gets option REQUEST_BODY_FILE - it reads the request body of the file. If there is no option - usually read request body of a protocol fastcgi.
tmpfs (linux): Along with this feature it makes sense to use "memory-based filesystem for temporary files, such as tmpfs (linux):
client_body_temp_path /dev/shm/client_body_temp;
fastcgi_finish_request()
Scope: php function Category: Optimization
This feature allows you to speed up implementation of some php queries. Acceleration is possible when there are actions in the process of script execution that do not affect server response. For example, saving the session in memcached can occur after the page has been formed and passed to a web server. fastcgi_finish_request() is a php feature, that stops the response output. Web server immediately starts to transfer response "slowly and sadly" to the client, and php at the same time can do a lot of useful things in the context of a query, such as saving the session, converting the downloaded video, handling all kinds of statistics, etc.
fastcgi_finish_request() can invoke executing shutdown function.
request_slowlog_timeout
Scope: directive php-fpm.conf Category: Convenience
The directive allows you to track the slow execution of scripts and record them in a log file along with the backtrace. For example, these settings
<value name="request_slowlog_timeout">5s</value>
<value name="slowlog">logs/slow.log</value>
record in slow.log might look like this:
Sep 21 16:22:19.399162 pid 29715 (pool default) script_filename = /local/www/stable/www/catalogue.php [0x00007fff23618120] mysql_query() /srv/stable/common/Database/class.MySQLRequest.php:20 [0x00007fff23618560] getResult() /srv/stable/common/Database/class.Facade.php:106 [0x00007fff23618aa0] query() /srv/stable/common/mysite.com/ORM/class.UsersMapper.php:99 [0x00007fff23618d60] resolveByID() /srv/stable/common/mysite.com/ORM/class.User.php:629 [0x00007fff236193b0] getData() /srv/stable/common/class.DataEntity.php:90 [0x00007fff236195d0] load() /srv/stable/common/mysite.com/ORM/class.User.php:587 [0x00007fff23619a00] getIsHidden() /srv/stable/common/mysite.com/class.User.php:42 [0x00007fff2361a470] getName() /local/www/stable/www/catalogue.php:41
At the same time in error.log saved this entry:
Sep 21 16:22:19.399031 [WARNING] fpm_request_check_timed_out(), line 135: child 29715, script '/local/www/stable/www/catalogue.php' (pool default) executing too slow (5.018002 sec), logging
As you can see from the example script is performed more than 5 seconds, and the most probable cause - the slow response mysql (top backtrace).
