Processing items in SQS queue with a php script

旧城冷巷雨未停 提交于 2019-12-11 05:16:06

问题


Here's my situation:

I have a script that gets raw data, saves it in the database, get the item id then posts it to an amazon SQS queue.

I have another script (written in PHP) that retrieves the raw data from the db and processes it. (it takes a couple of minutes usually.

The missing part is how to retrieve the messages from SQS to be processed. The frequency of new data to process varies, it can go from a few items per hours to dozens of items per minute.

One way would be to have a cron job that queries SQS for new messages and launch the processing script (It would have to be multi-threaded and written in something other than php. Python or Ruby perhaps). The problem wit the cron is that it is pretty inefficient, in high load phases it would be overwhelmed and in quiet phases it would be doing useless calls.

What I would like to have is some kind of multi-threaded listener that would receive messages and process them. One important requirement is to have the raw data processed in a timely manner, a couple of minutes after being received at most.

Any thoughts on the best solution? Is SQS appropriate for the task? What's the most efficient way to listen and process the queue?

来源:https://stackoverflow.com/questions/8203531/processing-items-in-sqs-queue-with-a-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!