I am writing a php script which will run through cron . Its task is to call other php scripts. The called scripts can also be executed externally. What I want is that while one file is executing, it should not be executed concurrently. To make things clear, consider following
Suppose there is one script master.php which calls to two other scripts script1.php and script2.php one after another. Now, once it called script1.php, it starts executing and take 10 mins to finish its processing. This Script1.php can also be run by user separately in these 10 mins.
What I want to do is while this script is amid its processing, it should not execute only parallely.
Is there a way to achieve this ? (Perhaps by checking the PID of script1.php).
Thanx in advance.
This is how I do it with a pid file. Also if the script is running for more than 300 seconds, it will be killed:
And then unlink the pid file at the end of the script:
If you want to run the script when the first instance finish – replace the exit() with sleep(1) and put the whole block in a loop.