Fatal error: Maximum execution time of 0 seconds exceeded - php

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

Related

Fatal error: Maximum execution time of 30 seconds exceeded. How to handle this error?

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

PHP Fatal error: Max execution time exceeded - EVEN after set_time_limit(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

PHP max execution time wrong

One of my PHP scripts is throwing the following error at me:
Fatal error: Maximum execution time of 30 seconds exceeded
The problem is that the script has only been executing for a few seconds.
I've timed everything between 2 and 10 seconds.
set_time_limit and ini_set('max_execution_time') have no effect (because of PHP safe mode).
Now I could just increase the value in my php.ini , but I would like to know why this error is thrown within a fraction of the actual maximum execution time.
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.
Or You can user set_time_limit(0) it will help only safemode.
This means that you might have an infinite loop somewhere or there is some code that has a timeout higher than 30 seconds.

PHP set_time_limit not working for exec

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!

Fatal error: Maximum execution time of 400 seconds exceeded

I have a PHP script that fails when executing a long mysq_query. The error message is:
Fatal error: Maximum execution time of 400 seconds exceeded in....
I use XAMPP for windows and I have changed the php.ini file (there is only one in my installation), setting max_execution_time to a large value that is not 400 seconds. Nevertheless I keep getting the error message above....
Any idea of how to solve this?
Thanks
Beto
As Ignacio says, something may be overriding the php.ini setting. You can definitively set the timeout for that script using set_time_limit
set_time_limit(600);
You can also set it to 0, which removes any time restriction - although this is not best practice.
400 seconds is a huge amount of time for a query - have you looked into adding indexes on commonly used columns in your db?
You need to restart your web server for PHP to re-parse your config file.
Something in either a .htaccess file or within a PHP script is probably resetting it back to 400 seconds.
Having said that, 400 seconds is still an excessive amount of time for a query. You should consider farming the task off to another process if it really needs to take that long.

Categories