Jump to content

Maximum Perl Script Execution Time On Shared Hosting?


SteveW

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");
}

Link to comment
Share on other sites

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...