开发者

Creating files on a time (hourly) basis

开发者 https://www.devze.com 2022-12-24 15:59 出处:网络
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.

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 a开发者_Python百科ppreciated :)


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");
    fwrite ($status,$fp);
    fclose($fp);
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消