-1

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?

BenMorel
  • 4,685

1 Answers1

2

It feels like you're trying to use the wrong architecture/tool for the job, and maybe you should look into using a message queue. beanstalkd has some PHP libraries available and will do blocking reads of the queue. There are some hints on how to proceed in this StackOverflow question.

nickgrim
  • 4,592
  • 1
  • 21
  • 28