简体   繁体   中英

Cron job to run PHP, that runs another PHP

I have a PHP script that runs server side via a CRON job. It functions just fine, but I need it to run every 10 seconds, not 60 seconds the limit of cron. Can I write another "Timer.PHP", that would call/run the UPDATE.PHP, and have the Timer.php loop and sleep to give me the 10 second update time? I could then have the cron run the Timer.php every 2 minutes.

The current cron job is: curl -s http://www.mysebsite.com/template/update/update.php?password=pass I am not sure of the following: 1) is this possible? 2) The correct syntax?

Someone suggested to have it loop 11 times (each loop 10 seconds apart) then stop until the cron calls it again. Their thoughts were to give it a 10 second down time to prevent the cron starting again before the previous one stopped its execution.

If you want to run it as a cron job, use php sleep() function. Run a loop 5 times and sleep the script for 10 seconds after execution. eg

<?php

for ($x = 0; $x < 5; $x++) {
    // Execute your code
    sleep(10);
}

?>

This is not a perfect solution but it'll work fine.

After several failed attempts, I decided it will be simpler to edit the actual PHP file that the cron job is currently properly executing. I will figure out how to loop it 6 times with a 10 second sleep. This will make it run 6 times with a 10 second delay. The cron can then restart the script again.

Thank you all for trying to help yet another newbie Bob

What I finally ended up doing is making 6 cron jobs, 5 have a sleep built into them.

1) Normal run 2) Sleep 10; 3) Sleep 20; 4) Sleep 30; 5) Sleep 40; 6) Sleep 50;

Fortunately my hosted server site allows this.
The script takes about 2 seconds to run. Been running this for over six hours so far with no errors. May not be the most glamorous solution, but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM