Reputation: 117
I have a php file I wrote that checks for new files in certain folders, then emails off the newest files since the last run. Sometimes this can be 10-15 files being attached to an email. I am using swiftmailer to send the emails.
This script can cycle through up to 50 customers, and each customer can have files which need to be emailed. Often times, this will timeout via PHP and throw an error. I've been trying to track where it left off by writing customer numbers to a file via php.
How can I use PHP to say "If there is an abrupt exit or error, then re-run this file."
Another way to say this is.... when I get a timeout error, or any other error, can I simply reload another PHP file to continue where I left off?
This doesn't seem like the cleanest way to accomplish my task, so I'm open to suggestions.
Upvotes: 0
Views: 120
Reputation: 28926
You can track the files to be processed by writing to a flat file or database, removing the entry for each file as it is completed. When the script restarts, read the list of files to be processed and continue where you left off.
Additionally, consider increasing the timeout setting in php.ini if you know that your script regularly requires more time.
In the event that you need to restart the script continually until the processing is completed, consider the following scenario:
The use of a PID file is not strictly necessary; you can get the same information by checking to see if the log exists and has entries. However, the use of a PID is traditional and provides a quick and cheap method of determining whether the previous process completed successfully.
Upvotes: 3