What is the best practice making a job queue system in php?
There are plenty of queue systems like beanstalkd, gearman, etc., but what if you want to run the daemon as a service on windows, and do the processing of the jobs, stored in a sql database, your self?
Mainl开发者_如何学JAVAy I'm asking for suggestions for the best method to process jobs, locking them, etc.
Try to use CRON + ScriptAlone
CAN/WANT ONLY DO IN PHP
If you really would want to do this in PHP/MySQL I would use
transactions
Put simply, a transaction is a series of SQL statements that are executed as a single unit; either all the statements are executed completely or none are executed at all.
- Add items to a queue tabel which is allready atomically
- remove items from queue by doing it inside a TRANSACTION(tutorial). first SELECT last item(FIFO). next DELETE that item with id(PK). But do this all inside of a transaction.
SHOULD CODE WITH OTHER LANGUAGE.
First of at all I would no do this in PHP, but in java if I was on the windows platform. I created a really simple message queue in java which I will package as a single jar and share with stackoverflow later when I have time.
精彩评论