Search code examples
phptimeoutfastcgi

How to handle timeouts with php5-fpm + nginx timeout php.ini


how to handle timeouts with PHP in php5-fpm + ngnix configurations?

I tried to make a simple script with just

sleep(60);

php.ini

max_execution_time = 30

fast_cgi

fastcgi_connect_timeout 60;
fastcgi_send_timeout 50;
fastcgi_read_timeout 50;

The script stops at 50s for timeout of the backend. What do I have to do to

  1. enable the max_execution_time in php.ini

  2. enable ini_set to change the execution time to 0 directly in the script

Why does fast_cgi get to control timeouts over everything instead of php itself?


Solution

  • It was basically the fact that on Linux the timeout counts only for the actual "php work" and not for all stream function times and moreover not for sleep that's why I never reached the limit and fastgci timeout always kicked in. Instead on Windows the actual "human" time elapsed counts.

    from the PHP doc:

    The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.