I’m discarding the old question for a better formulated question.
I’m using the twitter stream api via php like the script below.
When I run it via the command line. The script keeps running and when I hit ctrl+c the script stops.
Thats great and all, but i’d like to run it in the background. When a user creates a new search, the script below gets activated and stays running till a signal is given to sop. Just like the cli version, but in the background.
How do I achieve this?
Ok, here’s a piece of code:
$opts = array(
'http' => array(
'method' => 'POST',
'content' => 'track=ipad'
)
);
$context = stream_context_create($opts);
$stream = fopen('http://test@stream.twitter.com/1/statuses/filter.json','r', false, $context);
while (!feof($stream)) {
if (!($line = stream_get_line($stream, 200000, "\n"))) {
continue;
}
$tweet = json_decode($line);
// mysql query
}
I’m running it
This should be solved by running the php script as a daemon from commandline, there are alot of things to conisder tho.
A good start is Jeroen Keppens’ presentation PHP in the dark he did on multiple php conference.