I need to run scripts at dynamic times (coinciding with a datetime in a database). Any ideas how to accomplish this?
Example:
Database says tomorrow at noon in 1 in a datetime field, then i want to run the script tomorrow at noon.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A very simple approach is to have a cron-job call a PHP script every 1 minute, and have it check the database for things that need done. If something needs done NOW(), then do it and remove from database.
You need to consider things like locking, process stacking, multiple processes, etc… to make this robust. But if your need is simple, this is a simple way to make it work.
Add this to crontab:
And in /path/to/my/script.php
Note, this is not robust. A robust script would grab a record while locked, update it to a “processing” status, process it, and update it to a “complete” status. This means that multiple processes could work at this same time (even if accidental) and not duplicate jobs. Also, this means that a single failure would not stop the train.