I'm building an application where the sending of all notifications (email, SMS, fax) will be asynchronous. The application will write the notifications to the database, and a batch job will read these notifications and send them with the appropriate transport.
I was first reading at ways to run cron faster than the minute, and realized this was a bad idea.
The batch scripts are written in PHP, and I guess that writing a proper daemon would be quite an overhead (though I'm open to any suggestion, as PHP car run indefinitely as well).
What I have in mind is a solution that would:
- Run the PHP script every 5 seconds
- Check that the previous run has finished, or abort (never 2 concurrent batches running)
- Kill the script if live for more than
x
minutes (a security in case it hangs) - Start with the system (if a reboot occurs)
Any idea how to do this?