I have a strange behavior of the time limit mgmt in PHP (v5.4.13).
I set max_execution_time to 30 in php.ini, in my script I call:
set_time_limit(1000) ;
and to be sure it is set I call:
error_log (ini_get('max_execution_time'));
which returns me 1000. But now if I call a program with
exec("foobar.exe") ;
(A long program, it takes about 5 minutes to run), the script stop with an error in the log:
PHP Fatal error: Maximum execution time of 120 seconds exceeded
My problem is why this script stops after 120 seconds? Any ideas?
Check your php.ini to see if Safe_Mode is ON. If so, max_execution_time has no effect.
OK, I found the issue.
That was stupid:
Between my set_time_limit(1000); and my exec("..."); I called few functions. Looking deeper in these functions, what a surprise! a set_time_limit(120);
Thanks everybody for your help!
Related
I am getting this error while running one script.
I know it's about execution time and i had went through all answers too but i want to display custom message when this error occurs so that site doesn't break.
How to handle that error as i have kept error display off on my live site so footer is not loaded due to this error which stops breaking my site?
http://whois.icann.org/en/lookup?name=google.com
When you visit this site its displaying custom error message
You can either increase the maximum execution time by using set_time_limit() or by setting max_execution_time in the php.ini.
Also by setting set_time_limit to 0 you can remove the limit for exceution time.
And if you are using linux you can try with the function register_shutdown_function.This function will be called when the execution time limit is reached.
You can try to add this line of code in the file first:
set_time_limit(0)
You can always modify your php.ini file. There is a setting for maximum execution time.
Another way is to use ini_set function.
Another way is to put the max execution time in your htaccess file.
EDIT:
The max execution time is not an error and therefore not catchable.
Please check out this: http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p
Finally, there is always scope of fixing the scripts and putting lengthy processes into a queue.
you can exceed max execution time like this :
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
change below configuration in php.ini
max_execution_time = 600;
max_input_time = 120;
max_input_nesting_level = 64;
memory_limit = 128M;
ini_set('memory_limit', '-1');
ini_set('max_execution_time', '10000');
at the first line of your php code
I am downloading a JSON file from an online source and and when it runs through the loop I am getting this error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\temp\fetch.php on line 24
Your loop might be endless. If it is not, you could extend the maximum execution time like this:
ini_set('max_execution_time', '300'); //300 seconds = 5 minutes
and
set_time_limit(300);
can be used to temporarily extend the time limit.
I had the same problem and solved it by changing the value for the param max_execution_time in php.ini, like this:
max_execution_time = 360 ; Maximum execution time of each script, in seconds (I CHANGED THIS VALUE)
max_input_time = 120 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB by default)
I hope this could help you.
All the answers above are correct, but I use a simple way to avoid it in some cases.
Just put this command in the begining of your script:
set_time_limit(0);
I ran into this problem while upgrading to WordPress 4.0. By default WordPress limits the maximum execution time to 30 seconds.
Add the following code to your .htaccess file on your root directory of your WordPress Installation to over-ride the default.
php_value max_execution_time 300 //where 300 = 300 seconds = 5 minutes
Edit php.ini
Find this line:
max_execution_time
Change its value to 300:
max_execution_time = 300
300 means 5 minutes of execution time for the http request.
Your script is timing out. Take a look at the set_time_limit() function to up the execution time. Or profile the script to make it run faster :)
if all the above didn't work for you then add an .htaccess file to the directory where your script is located and put this inside
<IfModule mod_php5.c>
php_value post_max_size 200M
php_value upload_max_filesize 200M
php_value memory_limit 300M
php_value max_execution_time 259200
php_value max_input_time 259200
php_value session.gc_maxlifetime 1200
</IfModule>
this was the way I solved my problem , neither ini_set('max_execution_time', 86400); nor set_time_limit(86400) solved my problem , but the .htaccess method did.
We can solve this problem in 3 different ways.
1) Using php.ini file
2) Using .htaccess file
3) Using Wp-config.php file ( for Wordpress )
You can remove the restriction by seting it to zero by adding this line at the top of your script:
<?php ini_set('max_execution_time', '0'); ?>
Follow the path /etc/php5(your php version)/apache2/php.ini.
Open it and set the value of max_execution_time to a desired one.
To extend your max_execution_time you can use either ini_set or set_time_limit.
// Set maximum execution time to 10 seconds this way
ini_set('max_execution_time', 10);
// or this way
set_time_limit(10);
!! But be aware that, both functions restarts also counting of time script has already taken to execute
sleep(2);
ini_set('max_execution_time', 5);
register_shutdown_function(function(){
var_dump(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
});
for(;;);
//
// var_dump outputs float(7.1981489658356)
//
so if you want to set exact maximum amount of time script can run, your command must be very first.
Differences between those two functions are
set_time_limit does not return info whether it was successful but it will throw a warning on error.
ini_set returns old value on success, or false on failure without any warning/error
Maybe check for any thing that you have changed under the php.ini file.
For example I changed the ";intl.default_locale =" to ";intl.default_locale = en_utf8" in order to enable the "Internationalization extension (Intl)" without adding the "extension=php_intl.dll" then this same error occurred. So I suggest to check for similar mistakes.
Increase your script execution time by adding the following line at top of the PHP script.
ini_set('max_execution_time', 120); //120 seconds = 2 minutes
Reference has taken from Increase the PHP Script Execution Time
You can do it easily with WHM. Just got to:
WHM -> Service Configuration -> PHP configuration
editor-> max_execution_time=30
( 30 is default change it to whatever value u want)
set_time_limit($time_in_second); // 0 for unlimited time
I use this php function in run time if need to run a script for long.
Details here.
I have same problem in WordPress site,
I added in .htaccess file then working fine for me.
php_value max_execution_time 6000000
I have make some changes in my case in: xampp\phpMyAdmin\libraries\config.default.php
i have searched for : $cfg['ExecTimeLimit'] and change the value at right side...
You can change Right hand Value to any higher value, like '5000'. and it works.
Fatal error:Maximum execution time of 30 seconds exceeded in C:\inetpub\wwwroot*.php on line ##.
My php.ini already set to:
max_execution_time=3600
Error line executes a program which takes 2 minutes to execute: It looks like:
exec("C:/inetpub/wwwroot/program.cmd");
Note: It runs fine on sever, creates all output files nicely. But throws error to browser page.
(I restarted the server after changing php.ini file)
use this....
ini_set('max_execution_time', 0); // zero means takes its own time.
This will execute the php program till it is fully executed.
You can set the execution time dynamically on the same page like this-
ini_set('max_execution_time', 300);
Please add this line in your .htaccess file:
php_value max_execution_time 0
I keep running into the following PHP error when running my script
Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\apps\sqlbuddy1.3.3\functions.php on line 22
I already put this in my PHP file, and I STILL get this error message.
#set_time_limit(0);
Am I missing something?
Edit: This error only shows up after SEVERAL minutes, not after 30 seconds. Could something also be delaying its appearance?
set_time_limit() has no effect when running in safe_mode:
This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.
You can check the value of safe_mode and max_execution_time with phpinfo().
Given the facts that you are using Windows and experiencing the timeout later than 30s you might have somewhere else in your code a reset of the timeout (set_time_limit(30)):
The set_time_limit() function [..] 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.
Search your code for:
ini_set('max_execution_time', 30)
set_time_limit(30)
Rather than relying on the PHP file to change the php.ini settings, you should do it yourself. Find where the php.ini is kept for WAMP, and change/add this line:
max_execution_time = 500;
There is a PHP config that unallows the script to change the time_limit.
You can change your PHP behavior on php.ini file
My script compares 2 source trees, creates a map of possible changed files, compares MD5 hashes and creates a diff-package.
After 28000-29000 files, PHP terminates the script with error:
Fatal error: Maximum execution time of 0 seconds exceeded in /root/_PACKER-TESTER/core/diff.class.php on line 67 (standard in_array() call)
I already tried to set max_input_time to high value (or zero) - nothing.
Setting max_execution_time to 99999999999999 do nothing .... the same error.
Try setting max_input_time = -1 in php.ini, or using set_time_limit(-1). That worked for me without rebuilding PHP.
This article explains it nicely.
Problem solved, php build with litespeed api (lsapi) has extra env variable to determine max execute time - LSAPI_MAX_PROCESS_TIME (default is 300sec).
Try set_time_limit() and check in phpinfo() if you are able to set the time limit:
set_time_limit(60*60);phpinfo();exit;
I've found the "max execution time of 0 seconds exceeded" can be caused by the code going into an infinite loop.
For example:
while (true) { ... }
causes this error for me.
If it's not an environment variable (as mentioned previously) I would examine what's on the line number reported by php with the error