Restarting cron PHP script
Posted: Wed Jan 11, 2012 1:37 pm
I'm working on a PHP script that will be run daily via cron. My concern is that the PHP execution time limits may be reached, so am looking for the best possible way to re-start the PHP script from within itself. I was thinking of using exec(), but not sure if this is the right way to go about it, or if it's even possible. I.e.
Suggestions?
Also, I've seen extensions used for exec() and am not sure of how these could be used to track issues:
Questions:
- Is the "nohup" needed?
- Should any/all of the "-q" and/or "< /dev/null" and/or trailing "&" be included?
- Should script.out and script.err be prefaced with the full path (i.e. /home/myaccount/cron/script.out)?
Thanks in advance for any help/suggestions.
- Code: Select all
<?php
if ($restart) {
// cron command is: php -q /home/myaccount/cron/script.php
exec('php -q /home/myaccount/cron/script.php');
exit;
}
else {
// rest of script
}
?>
Suggestions?
Also, I've seen extensions used for exec() and am not sure of how these could be used to track issues:
- Code: Select all
<?php
exec('nohup php -q /home/myaccount/cron/script.php > script.out 2> script.err < /dev/null &');
?>
Questions:
- Is the "nohup" needed?
- Should any/all of the "-q" and/or "< /dev/null" and/or trailing "&" be included?
- Should script.out and script.err be prefaced with the full path (i.e. /home/myaccount/cron/script.out)?
Thanks in advance for any help/suggestions.