Set ini max_execution_time not working

Before using nginx and php-fpm, I used Apache, so when I wanted only one of my cron jobs to run without a run time limit, I used these lines in my PHP code:

set_time_limit(0); ini_set('max_execution_time', 0); 

but after switching from Apache to nginx this code does not work. I know how to modify nginx.conf to increase the maximum runtime.

But I want to handle this with php code. Is there any way? I want to specify only one file that can run PHP code without a time limit.

+6
source share
4 answers

Try the following:

Increase PHP script runtime with Nginx

You can follow the steps below to increase the timeout value. PHP defaults to 30 seconds .:

Changes in php.ini

If you want to change the maximum runtime for php scripts from 30 seconds (default) to 300 seconds.

 vim /etc/php5/fpm/php.ini 

Set ...

 max_execution_time = 300 

In Apache, applications working with PHP as a module above would be sufficient. But in our case, we need to make this change in two more places.

PHP-FPM Changes

This is only necessary if you have not already commented on the request_terminate_timeout parameter. It is commented out by default and takes the value max_execution_time found in php.ini

Edit ...

 vim /etc/php5/fpm/pool.d/www.conf 

Set ...

 request_terminate_timeout = 300 

Nginx configuration changes

To extend the term for example.com by

 vim /etc/nginx/sites-available/example.com location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_read_timeout 300; } 

If you want to increase the time limit for all sites on your server, you can edit the main nginx.conf file:

 vim /etc/nginx/nginx.conf 

Add to http section {..}

 http { #... fastcgi_read_timeout 300; #... } 

Update PHP-FPM and Nginx

Do not forget to do this so that the changes you have made take effect:

 service php5-fpm reload service nginx reload 

or try

 fastcgi_send_timeout 50; fastcgi_read_timeout 50; 

fastcgi has its own set of timeouts and checks to prevent it from being disabled when a process is blocked. They will kick if, for example, you set the php runtime limit to 0 (unlimited), and then accidentally create an infinite loop. Or if you used some other application besides PHP, which did not have any of its own timeout protections, and it failed.

+16
source

I think that if you have php-fpm and nginx, "you cannot" set this time only with PHP.

What you can do is redirect with parameters indicating where to continue, but you have to control the running time of your script to avoid a timeout.

If your process is running in a browser window, do it using Javascript, as the browser can limit the number of redirects ... or do it using ajax.

Hope this helps.

+2
source

You can add request_terminate_timeout = 300 to the php-fpm server pool configuration if you try all the solutions here.

0
source
 ini_set('max_execution_time', 0); 

do this if Safe Mode is turned off

 set_time_limit(0); 

Put this at the top of your PHP script and let your script free!

Note. if your PHP installation is running in safe mode, you can only change it from the php.ini file.

-1
source

All Articles