PHP max execution time wrong - php

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.

Related

Php maximum executing time keeps increasing

I have a script in php which takes data from a database and writes it in a file. The first time I ran the script I got this:
Fatal error: Maximum execution time of 240 seconds exceeded.
So I changed this time in my php.ini to 300 and ran the script again. This time, it works. However, on running the script a second time I get this error:
Fatal error: Maximum execution time of 300 seconds exceeded.
After changing the time to 300 now, it works again but only the first time.
Any idea as to why I have to keep on increasing this max_execution_time?
At the beginning of your script you can add.
ini_set('MAX_EXECUTION_TIME', -1);
This line of code will drop the max execution time restriction of a code, allowing a php code to run forever.

Php and max_execution_time

I need to one of my script (not all) works only five second. And if execution not finished yet (within five seconds) it should be dropped.
So I use
ini_set('max_execution_time', 5);
Also if I do
ini_get('max_execution_time');
it shows me five second, but script not interrupt after 5 seconds.
P.S
safe_mode = off
nginx -> php-fpm
set_time_limit(5) also has no effect
You can use set_time_limit function on top in your code as follows:
set_time_limit(5)
NB: If you dont place it on top of your code, supposed the php script has ran for 3 seconds and you called set_time_limit(5) so the total time of allowed execution would be 3+5 = 8 sec not 5sec as expected
Update
From php documentation:
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.

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 value is 30seconds but run 200seconds?

im getting php maximum execution time like this.
<?php ini_get('max_execution_time'); ?>
output: 30
but i can run this script.
<?php
sleep(200);
echo "no timeout error";
?>
output: no timeout error
im how to get real ini value ?
best regards
From the manual:
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.
Since sleep is a system call, it doesn't count against the max execution time.
Your max_exec_time IS 30 seconds, but it's not timeouting because time is not running in sleep() but only when script is doing something

time of 30 seconds exceeded error? file get contents

i have this error:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\AppServ\www\facebook\classes\burccek.class.php on line 56
(im using file_get_contents)
(in this program i post file_get_contents data to facebook user wall(offline_access))
It means the file_get_contents operation takes more time that the max execution time of PHP. If you need a longer time, add this line at the top of your file: set_time_limit($seconds);
However 30 seconds seems a long time already so there might be some other issue with your application.
If duration of posting file to FB is longer than 30s (default maximum execution time of php script), use
set_time_limit ( 120 );
(or more in seconds) before executing file_get_contents
When posting data to other URLs, you should rely on CURL or even in extreme case may go to socket level. Curl has better control on connection time outs to handle network latency, much more set of options. In some hosting environments or servers a sys admin may restrict what all php.ini settings you can change, though you can change set_time_limit
You can change your set_time_limit in your php.ini file to alter the maximum execution time that php can use for a script.

Categories