Reese
Reese

Reputation: 1775

php workers or queue processor

Background/problem description:

I'm not even sure how to search for what I want to do. I have a queue of items that need to be processed, and I want PHP to check every 10 seconds (or whatever increment) to see if there is anything in the queue. If there is, it should begin processing it, but only if it isn't already processing another item (so, when processing takes 30 seconds, for example, it wouldn't have more than one item being processed). I think I can hack an 'already processing' flag with the existence of a lock file or something.

I'm probably going to be using AWS SQS for the queue, and have multiple servers running in parallel

The question:

Basically, the user needs to queue up a bunch of work to be done asynchronously. So my question is, how do you schedule PHP to do queue checking? I was looking at cronjobs, but those seem to only be capable of running every minute.

Upvotes: 2

Views: 1407

Answers (1)

I would start with a simple loop. Every 10 seconds, the loop checks the queue. If there is something there it processes it, taking whatever time is necessary. When the processing finishes, the loop continues in the 10 second loop.

Upvotes: 2

Related Questions