Increase max execution time for php

Php.HtaccessScriptingPhp Ini

Php Problem Overview


I have added set_time_limit(0); function to increase execution time but its executing only 2-3 minutes maximum.

error_reporting(E_ALL);
error_reporting(1);
set_time_limit(0);

I want to search links from a site which is taking a long time.

Php Solutions


Solution 1 - Php

PHP file (for example, my_lengthy_script.php)

ini_set('max_execution_time', 300); //300 seconds = 5 minutes

.htaccess file

<IfModule mod_php5.c>
php_value max_execution_time 300
</IfModule>

More configuration options

<IfModule mod_php5.c>
php_value post_max_size 5M
php_value upload_max_filesize 5M
php_value memory_limit 128M
php_value max_execution_time 300
php_value max_input_time 300
php_value session.gc_maxlifetime 1200
</IfModule>

If wordpress, set this in the config.php file,

define('WP_MEMORY_LIMIT', '128M');

If drupal, sites/default/settings.php

ini_set('memory_limit', '128M');

If you are using other frameworks,

ini_set('memory_limit', '128M');

You can increase memory as gigabyte.

ini_set('memory_limit', '3G'); // 3 Gigabytes

259200 means:-

( 259200/(60x60 minutes) ) / 24 hours ===> 3 Days

More details on my blog

Solution 2 - Php

Add these lines of code in your htaccess file. I hope it will solve your problem.

<IfModule mod_php5.c>
php_value max_execution_time 259200
</IfModule>

Solution 3 - Php

Well, since your on a shared server, you can't do anything about it. They usually set the max execution time so that you can't override it. I suggest you contact them.

Solution 4 - Php

well, there are two way to change max_execution_time.

  1. You can directly set it in php.ini file.

  2. Secondly, you can add following line in your code.

    ini_set('max_execution_time', '100')

Solution 5 - Php

Use mod_php7.c instead of mod_php5.c for PHP 7

Example

<IfModule mod_php7.c>
   php_value max_execution_time 500
</IfModule>

Solution 6 - Php

There's probably a limit set in your webserver. Some browsers/proxies will also implement a timeout. Invoking long running processes via an HTTP request is just plain silly. The right way to solve the problem (assuming you can't make the processing any faster) is to use the HTTP request to trigger processing outside of the webserver session group then poll the status via HTTP until you've got a result set.

Solution 7 - Php

This is old question, but if somebody finds it today chances are php will be run via php-fpm and mod_fastcgi. In that case nothing here will help with extending execution time because Apache will terminate connection to a process which does not output anything for 30 seconds. Only way to extend it is to change -idle-timeout in apache (module/site/vhost) config.

FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /run/php/php7.0-fpm.sock -idle-timeout 900 -pass-header Authorization

More details - https://stackoverflow.com/questions/40360922/increase-php-fpm-idle-timeout-setting/41453173#41453173

Solution 8 - Php

Try to set a longer max_execution_time:

<IfModule mod_php5.c>
    php_value max_execution_time 300
</IfModule>

<IfModule mod_php7.c>
    php_value max_execution_time 300
</IfModule>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBajrangView Question on Stackoverflow
Solution 1 - PhpSumith HarshanView Answer on Stackoverflow
Solution 2 - PhpSalman AslamView Answer on Stackoverflow
Solution 3 - PhpMobView Answer on Stackoverflow
Solution 4 - PhpNishu TayalView Answer on Stackoverflow
Solution 5 - PhpPrestaSharkView Answer on Stackoverflow
Solution 6 - PhpsymcbeanView Answer on Stackoverflow
Solution 7 - PhpsevenView Answer on Stackoverflow
Solution 8 - PhpJefferson SchiavettoView Answer on Stackoverflow