Reputation: 219
I have a PHP script that run on cron every 5 minutes.
*/5 * * * * /var/www/html/processMail.php
Inside the script there is a function that I want to execute every 15 minutes, so that function will be in sleep mode but the rest of the script will be process every 5 minutes.
does this crazy idea will work and how?
Upvotes: 2
Views: 3498
Reputation: 175088
You could save an iterator in a file or a database and increment it after every run, this way you can only run it once in 3 times the script runs.
However, a much better solution would simply be to write another script and run it every 15 minutes.
Upvotes: 1
Reputation: 198214
does this crazy idea will work and how?
No it won't. The each 15 minute function would - even if you manage to wait 15 minutes - be executed each 5 minutes - so effectively the 15 minutes function is executed each 5 minutes. Instead create a second script that is executed every 15 minutes or add a parameter:
*/5 * * * * /var/www/html/processMail.php --mins=5
*/15 * * * * /var/www/html/processMail.php --mins=15
Then use the functionality to parse commandline-parameters in PHP (and getopt
) to process accordingly. See as well the section about commandline usage in the PHP manual.
Upvotes: 4