views:

44

answers:

2

Hi there,
I experimenting with twitter streaming API,
I use Phirehose to connect to twitter and fetch the data but having problems storing it in files for further processing.
Basically what I want to do is to create a file named

date("YmdH")."."txt"  

for every hour of connection.

Here is how my code looks like right now (not handling the hourly change of files)

public function enqueueStatus($status)
$data = json_decode($status,true);
if(isset($data['text'])/*more conditions here*/) {
  $fp = fopen("/tmp/$time.txt");
  fwirte ($status,$fp);
  fclose($fp);
}

Help is as always much appreciated :)

+1  A: 

You want the 'append' mode in fopen - this will either append to a file or create it.

if(isset($data['text'])/*more conditions here*/) {
    $fp = fopen("/tmp/" . date("YmdH") . ".txt", "a");
    fwirte ($status,$fp);
    fclose($fp);
}
stereofrog
A: 

From the Phirehose googlecode wiki:

As of Phirehose version 0.2.2 there is an example of a simple "ghetto queue" included in the tarball (see file: ghetto-queue-collect.php and ghetto-queue-consume.php) that shows how statuses could be easily collected on to the filesystem for processing and then picked up by a separate process (consume).

This is a complete working sample of doing what you want to do. The rotation time interval is configurable too. Additionally there's another script to consume and process the written files too. Now if only I could find a way to stop the whole sript, my log keeps filling up (the script continues execution) even if I close the browser tab :P

Paganwinter