Main Topics
Browse All TopicsHello,
I have some scripts running on a debian server, called by various cronjobs, wich call php scripts.
Sometimes the php scripts are stucked for some hours, and I need to avoid it.
I already use the trap mechanism to avoid overlapping of the scripts, but in the cases of previous cron beeing stucked, nothing is working anymore.
I attach the code of the bash script. Cannot give you the php scripts, wich is very huge and access mysql database, lucene/solr engine, and files.
The ideal solution could be to stop the execution of the php if the time exceed the delay param.
I know I could kill the previous cron if i find the lockfile, but this seems bad practice.
Any help appreciated.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Like explained in the documentation :
"Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running."
Sorry, didn't totally understand.
The easiest way I can think of is to set a variable with the start time at the beginning of the script, and then check it in a loop that includes the rest of the script.
Something like this (in pseudocode):
<?php
$timelimit = 360; //number of seconds to run
$starttime = time(); //current time at start
do
{
//rest of script
}
while ( (time() - $starttime) < $timelimit ); //stop when current time is $timelimit beyond start time
exit();
?>
I already have this in the php script; but when it gets stucked, it is on a socket call or other stuff regarding third party libraries, and the loop isn't looping anymore.
I can't find out all the socket calls in libraries and set a timeout, or whatever. That's why I really want something over php to handle this (in the linux bash script).
BTW thx for your help.
Business Accounts
Answer for Membership
by: yodercmPosted on 2009-08-10 at 11:07:46ID: 25062374
set_time_limit(360);