Reputation: 997
I hvave a cron job that is doing some updates. After completion of that process i need to run another cron job for inserting that updated records into another table.For this I am trying this script.
$output = shell_exec('ps -C php -f');
if (strpos($output, "php do_update.php")===false) {
shell_exec('php insert_process.php');
}
But it is not doing any thing and i am getting ps is not internal / external command. So how can I find that first cron job execution is completed or not?Once that is executed then i will run the second cron for inserting data. Any holp would be greatly appreciated.
Upvotes: 0
Views: 57
Reputation: 6311
you can use flock
on running the do_update.php
add a lock to it and in
`insert_process.php` run the process if your previous lock is released
in your do_update.php
add this
$fp = fopen("lock.txt", "r+");
if (flock($fp, LOCK_EX)) {
//do your process
flock($fp, LOCK_UN); //release the lock
}
in your insert_process.php
add this
$fp = fopen("lock.txt", "r+");
if (flock($fp, LOCK_EX | LOCK_NB)) { // checks for the lock
// do your process
}
Upvotes: 1
Reputation: 939
You could use some kind of a lock file.
First file:
lockfile.txt
(or any other name)Second file
lockfile.txt
exists, if not - run the codeUpvotes: 1