Jump to content

[SOLVED] Fatal error: Maximum execution time of 30 seconds exceeded


eon201

Recommended Posts

Hi,

 

Im (still) building my stats builder. After much battling I have finally got my code to read in the server log file line by line in reverse without commiting the whole log file to memory by reading the whole thing (if it did the server woul die as the files are HUGE). Once each line has been read the php passes this info to the mysql to be picked up at a later point.

 

It all works fine, and im happy with my progress.

 

The only problem? It exceeds the maximum execution time and just stops working! How can I solve this? Is there a way to set the server to let one file run over the 30 secs, or is there a problem in my code??

 

Thanks in advance. Eon201.

Link to comment
Share on other sites

It is

<?php set_time_limit ( int seconds ); ?>

 

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. If seconds is set to zero, no time limit is imposed.

set_time_limit() 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.

 

Link to comment
Share on other sites

From the manual

The set_time_limit() function lets you arbitrarily set how long a script should take to execute. This value is usually set inside php.ini under the max_execution_time setting, however you can override that here. The function takes one parameter, which is the number of seconds you want the script to have, or you can pass 0 which means "let the script run as long as it needs". Here it is in action, setting the script execution time to 30 seconds:

set_time_limit(30);

 

Note that most web servers have their own time limit. In Apache, for example, this is set under "Timeout" in httpd.conf, and defaults to 300 seconds . If you use set_time_limit() to a value greater than Apache's timeout value, Apache will stop PHP before PHP stops itself. Also note that PHP may let some scripts go over the time limit if control is outside the script. For example, if you run an external program that takes 100 seconds and you have set the time limit to 30 seconds, PHP will let the script carry on for the full 100 seconds and terminate immediately afterwards. This also happens if you use the sleep() function with a value larger than the amount of time the script has left to execute.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.