SteveW Posted December 6, 2010 Share Posted December 6, 2010 My script tracks its execution time and quits if a specified time limit is reached. It's currently limited to 1 second, which seems safe enough for testing but might not be sufficient later. At what point would I be impacting server performance? Maximum execution time for PHP scripts appears to be 30 seconds by default, but is that pushing the limit of what's acceptable? It's also configured so that when one instance of the script starts running, it creates a flag file that prevents any other instances from being launched until it finishes. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted December 6, 2010 Share Posted December 6, 2010 Steve, only the techs would be answer this one. I would think anything less than 30 would be fine. Quote Link to comment Share on other sites More sharing options...
TCH-Alex Posted December 6, 2010 Share Posted December 6, 2010 The maximum execution time is set to 30 seconds by default configuration, you can run the php script to this time. However, please note that the usage of server resource (cpu, memory) are more sensitive than maximum execution time. Also, you can change the maximum execution time of a php file with the keyword set_time_limit() inside the script or setting max_execution_time on .htaccess or local php.ini file Quote Link to comment Share on other sites More sharing options...
SteveW Posted December 7, 2010 Author Share Posted December 7, 2010 Time/CPU/Memory were all things I'm concerned about, but time is the only one I currently know how to measure and control. I'm assuming the techs won't be shy about disabling the script and informing me if it causes any problem. In case it's any use to someone in the future, this is how I make the script time itself out instead of waiting for the system to do it: > my $maxseconds = 1; # time limit in seconds. 0=no limit. my $starttime = time(); # Now, reference time. my $timedout = 0; # bool flag. my $elapsed = 0; # elapsed time. # Inside a loop, the program accumulates output over multiple levels of processing. # If processing exceeds the time limit before finishing the task, it exits the loop, # but the script will still go on to print whatever output it has. # The task is able to partially or mostly complete, less disruptive than # if the system forcibly terminates it (?). for(something) { do_something(); if($maxseconds > 0) { $elapsed = time() - $starttime; if($elapsed > $maxseconds) { $timedout = 1; last; } } } print("$output\n"); if($timedout) { print("\nOutput is partial due to time limit exceeded.\n"); } 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.