How do you sequence tasks in PHP?

Let’s say for example that I’m querying the Twitter API for tweets on a particular topic, which is initiated by a user search. What I then want to do is query the API again, say every 10 minutes for the next hour, and save any new tweets that have come in on the same subject.

Once the user has initiated the process by running the first search, what are the mechanics for implementing that sequence of repeated searches? What do you do to make that happen, without any further activity from the user?

That sounds like an excellent job for beanstalkd. Here is a nice intro to it: http://abulman.co.uk/presentations/Beanstalkd-2010-05-06/

Basically what you want to do when a user searches something is to add 6 messages to the queue, one in 10 minutes, the next in 20, then 30, 40, 50 and 60. In the background you have a PHP script that waits for messages back from beanstalkd and can than do anything you want it to (in your case, you wire it to a script that searches the twitter API).

There are other queueing systems you can use, but beanstalkd is nice and easy to learn and should should suffice for your purposes :slight_smile:

That does look like it might do the trick, yes – thanks for the link.