hey, i´m running php-fpm + nginx with one problem.
whenever a client closes its browser tab, or when the script takes to long to process and an nginx read timeout accours, the php-fpm process working on this request is not killed.
why is this, how can i stop this?
here are some informations about my system:
OS: scientifix linux 6 (rhel clone)
nginx: nginx-0.8.54-1.el6.x86_64 (epel repo)
php-fpm: php-fpm-5.3.10-2.el6.remi.x86_64 (remi repo)
php setting:
php.ini & php-fpm settings are set to default values, except max_execution_time set to 360
nginx sample configuration:
/etc/nginx/nginx.conf:
########################################################################
worker_processes 1;
worker_rlimit_nofile 60000;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# define format for combined logs with response times:
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'TOTAL: $request_time UPSTREAM: $upstream_response_time PIPE: $pipe'
'UPSTREAM_SERVER: $upstream_addr UPSTREAM_STATUS: $upstream_status';
# $https_on used in proxy_set_header
map $http_x_https $https_on {
default off;
https on;
}
#Mime types
include mime.types;
#Common options
#include options.conf;
#Proxy settings
#include proxy.conf;
#default host:
include /etc/nginx/conf.d/default.conf;
#domains in alphabetical order
include /etc/nginx/conf.d/test/default.conf;
}
########################################################################
/etc/nginx/conf.d/test/default.conf:
########################################################################
server {
allow all;
listen 8000;
server_name test.local;
root /home/nginx/test/default/public;
access_log /home/nginx/test/logs/default_access.log;
error_log /home/nginx/test/logs/default_error.log notice;
rewrite_log on;
server_name_in_redirect off;
port_in_redirect off;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
include /etc/nginx/conf.d/eol/quicker/test/global_env.conf;
fastcgi_read_timeout 60;
fastcgi_pass 127.0.0.1:9000;
}
}
########################################################################
sample timeout script:
<?php
$LOOP_COUNT = 14;
$MY_PID = getmypid();
$MY_PID = $MY_PID."_timeoutscript";
$SLEEP_TIME = 10;
function getTime()
{
$a = explode (' ',microtime());
return(double) $a[0] + $a[1];
}
$Start = getTime();
echo "[$MY_PID] startet php script\n";
error_log( "[$MY_PID] startet php script\n");
echo "[$MY_PID] entering for loop; will loop $LOOP_COUNT times\n";
error_log("[$MY_PID] entering for loop; will loop $LOOP_COUNT times\n");
for($i=1; $i <= $LOOP_COUNT; $i++)
{
echo "[$MY_PID] this is loop $i; running \n";
error_log("[$MY_PID] this is loop $i; running \n");
sleep($SLEEP_TIME);
echo "[$MY_PID] this is loop $i; finished \n";
error_log("[$MY_PID] this is loop $i; finished \n");
}
$End = getTime();
$TIME_TAKEN=number_format(($End - $Start),2);
echo "[$MY_PID] script finished; took $TIME_TAKEN secs\n";
error_log("[$MY_PID] script finished, took $TIME_TAKEN secs\n");
?>
now when you call this script, the nginx fastcgi_read_timeout will send a http 504 to the browser, but the script will continue in the background.
also, when the client aborts the request in the browser, nginx/php-fpm will not stop the request.
you can follow this by tailing the php_error log & watch for "_timeoutscript"
i know that i could set max_execution_time to a lower value, but this wont help with client aborts. and in my reald world application i have some locations that need these high values.
cheers
schlitzer