Created
November 21, 2013 11:14
-
-
Save WyriHaximus/7579897 to your computer and use it in GitHub Desktop.
This bit of react/http-client listens on the twitter streaming API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$buffer = ''; | |
$request = $this->client->request($method, $url, $headers); | |
$request->on('response', function($response) use (&$buffer) { | |
$response->on('data', function($data) use (&$buffer) { | |
$buffer .= $data; | |
if (strpos($buffer, PHP_EOL) !== false) { | |
$tweets = explode(PHP_EOL, $buffer); | |
$buffer = array_pop($tweets); | |
foreach ($tweets as $tweet) { | |
if (strlen(trim($tweet)) > 0) { | |
$tweetObject = json_decode($tweet); | |
$this->saveTweet($tweetObject); | |
} | |
} | |
} | |
}); | |
}); | |
$request->end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I look forward to giving this a try with our campfire chatroom.. hopefully using SSL isn't harder.