Didn’t see a question similar to this, so here goes:
Let’s say I’m running a cron script, and it has the potential to run out of memory (64M) or time (30 seconds). Is there a way for the script to detect this and restart itself, or redirect to itself?
I’m assuming this is running on some sort of unix so if you wrap your php call with something like this:
Your timed cron will re-start the script every time, as long as it’s not still running.
Another option is to optimize your script. If it’s infinitely looping
while(true) {}and running out of ram, it’s doing something bad and be managed accordingly.If you’re running out of time, you should set
max_execution_timeviaset_time_limit()0 for your CLI script.