eon201 Posted November 29, 2007 Share Posted November 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 29, 2007 Author Share Posted November 29, 2007 Just remembered. I know there is a way to set the timout limit in the initial <?php tag. Does anyone know the code for this? Thanks again! Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 29, 2007 Share Posted November 29, 2007 Maybe ini_set() (I think it's that). Not sure how exactly, though. Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 29, 2007 Share Posted November 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
aschk Posted November 29, 2007 Share Posted November 29, 2007 set_time_limit(INTEGER); Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 29, 2007 Author Share Posted November 29, 2007 I take it the integer is in seconds? Whoops. Just saw ~n[EO]n~'s post! Thanks for the help guys! Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 29, 2007 Author Share Posted November 29, 2007 Sorry to be a pain. Will this overide the server setting of a 30 sec time limit if I set it to anything over 30 secs? Quote Link to comment Share on other sites More sharing options...
Aureole Posted November 29, 2007 Share Posted November 29, 2007 I'm pretty sure it does but don't abuse it or you'll own your server. Quote Link to comment Share on other sites More sharing options...
eon201 Posted November 29, 2007 Author Share Posted November 29, 2007 Yer just tested it. It does overide. Thanks guys! Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 29, 2007 Share Posted November 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.