Best way to continue a timed out script in php? -


i have php file wrote checks new files in folders, emails off newest files since last run. can 10-15 files being attached email. using swiftmailer send emails.

this script can cycle through 50 customers, , each customer can have files need emailed. times, timeout via php , throw error. i've been trying track left off writing customer numbers file via php.

how can use php "if there abrupt exit or error, re-run file."

another way is.... when timeout error, or other error, can reload php file continue left off?

this doesn't seem cleanest way accomplish task, i'm open suggestions.

you can track files processed writing flat file or database, removing entry each file completed. when script restarts, read list of files processed , continue left off.

additionally, consider increasing timeout setting in php.ini if know script regularly requires more time.

in event need restart script continually until processing completed, consider following scenario:

  • start script via cron every 5 minutes (or appropriate interval)
  • the script writes pid file
    • if script finds pid file exists, previous script crashed, start processing log again.
  • check database last successful run time.
    • if last successful run time less minimum (the interval @ run script), delete pid , exit.
    • if last successful run time more minimum, process files, delete pid, , exit.

the use of pid file not strictly necessary; can same information checking see if log exists , has entries. however, use of pid traditional , provides quick , cheap method of determining whether previous process completed successfully.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -