I put my code on sleep when no data returned by server. But it gives me this error after a while being idle.
<b>Fatal error</b>: Maximum execution time of 120 seconds exceeded in
I know, changing the max limit in php.ini would help. But i don't want to do this, because I don't own the server...so I can't be changing each clients server limit.
how can I set the max limit to infinity here or probably how to reconnect if reached max?
while ($currentmodif <= $lastmodif)
{
usleep(10000); // sleep 10ms to unload the CPU
clearstatcache();
$currentmodif = filemtime($filename);
}
You'll have to set it to zero. Zero means the script can run forever. Add the following at the start of your script:
ini_set('max_execution_time', 0);
set_time_limit() does not return anything so you can't use it to detect whether it succeeded. Additionally, it'll throw a warning:
Warning: set_time_limit(): Cannot set time limit in safe mode
ini_set() returns FALSE on failure and does not trigger warnings.
Related
Is there any way to set php max execution time less than a second?
or
How can we handle it in code level like return a json message to show "Exceeded max allowed response time"?
No, you can't set max_execution_time less than the seocond. Also, You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.
max_execution_time
But you can emulate it with a function as this post
declare(ticks=1);
$start = microtime(1);
register_tick_function(function () use ($start) {
(microtime(1) - $start < 0.8) or die();
});
I use joomla connect to postgresql:
$db = JFactory::getDBO();
$db->setQuery($query);
$db->query();
$object = $db->loadAssocList();
Default timeout=30s. I want set timeout =120.
How set timeout of query? Thanks.
set_time_limit
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini.
When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.
you need to use the standard php function
set_time_limit(120);
I've written a basic indexing script for my site and it seems to be working...somewhat. It gets through about 3/4 of the pages it needs to index and then give this error:
Fatal error: Maximum execution time of 0 seconds exceeded in
/Zend/Search/Lucene/Analysis/Analyzer.php on line 166
It seems to hang up in a different spot each time, too. I ran it a minute later and got this:
Fatal error: Maximum execution time of 0 seconds exceeded in
/Zend/Search/Lucene/Storage/Directory/Filesystem.php on line 349
Here's the script:
foreach($all_items as $item) {
$doc = new Zend_Search_Lucene_Document();
$doc->addField(Zend_Search_Lucene_Field::Text('title', $item['pagetitle']));
$doc->addField(Zend_Search_Lucene_Field::Text('url', $item['url']));
$doc->addField(Zend_Search_Lucene_Field::Text('country', $item['country']));
// Add document to the index
$index->addDocument($doc);
}
Maybe your task is time consuming?
Then increase time limit set_time_limit:
set_time_limit(0); //no time limit
set_time_limit(500) //500 sec limit
Try increasing max_execution_time
ini_set('max_execution_time', 5000);
There is also max_input_time
ini_set('max_input_time', 5000);
If it still does not work, you will need to track down parts what is executing forever
2 questions for PHP in Linux:
1.) will register_shutdown_function be called if a script exceeds the maximum time limit for the script to run?
2.) if #1 is true, how can I test a script going beyond its max time limit if sleep() doesn't count towards execution time?
A function registered with register_shutdown_function will be called when the execution time limit is reached. You can test the limit with a busy wait:
<?php
register_shutdown_function(function() {
echo "shutdown function called\n";
});
set_time_limit(1); // Set time limit to 1 second (optional)
for (;;) ; // Busy wait
Is it possible to get Max Execution timeout notification so that i can use code clean up operations before the php script stops running?
Basically, i am trying to create a script that can do some changes/modifications to my database which has huge data pile. Also, this php script execution can be paused/resumed using a filelock.
You can either use set_error_handler() or register_shutdown_function().
Edit: See also: max execution time error handling
If you set 0 to set_time_limit, it will never stop :)
You can increase the limit time inside your code using:
set_time_limit(300); //time in seconds
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
or
changing the max_execution_time parameter inside your php.ini.
The default time is 30 seconds.