Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good distributed queue managers in php?

I'm working an image processing website, instead of having lengthy jobs hold up the users browser I want all commands to return fast with a job id and have a background task do the actual work. The id could then be used to check for status and results (ie a url of the processed image). I've found a lot of distributed queue managers for ruby, java and python but I don't know nearly enough of any of those languages to be able to use them.

My own tests have been with shared mysql database to queue jobs, lock them to a worker, and mark them as completed (saving the return data in the db). It was just a messy prototype, and the entire time I felt as if I was reinventing the wheel (and not very elegantly). Does something exist in php (or that I can talk to RESTfully?) that I could use?

Reading around a bit more, I've found that what I'm looking for is a queuing system that has a php api, it doesn't have to be written in php. I've only found classes for use with Amazon's SQS, but not only is that not free, it's also quite latent sometimes (over a minute for a message to show up).

like image 509
reconbot Avatar asked Mar 18 '09 18:03

reconbot


2 Answers

Have you tried ActiveMQ? It makes mention of supporting PHP via the Stomp protocol. Details are available on the activemq site.

I've gotten a lot of mileage out of the database approach your describing though, so I wouldn't worry too much about it.

like image 198
Mat Schaffer Avatar answered Oct 30 '22 14:10

Mat Schaffer


Do you have full control over server?

MySQL queue could be fine in such case. Have a PHP script that is running constantly (in endless while loop), querying the MySQL database for new "tasks" and sleep()ing in between to reduce the load in idle time.

When each task is completed, mark it in the database and move to the next one.

To prevent that whole thing stops if your script crashes/exists (PHP memory overflow, etc.) you can, for example, place it in inittab (if you use Linux as a server) and init will restart it automatically.

like image 39
Milan Babuškov Avatar answered Oct 30 '22 15:10

Milan Babuškov