* @param string $status */ public function enqueueStatus($status) { /* * In this simple example, we will just display to STDOUT rather than enqueue. * NOTE: You should NOT be processing tweets at this point in a real application, instead they * should be being enqueued and processed asyncronously from the collection process. */ $data = json_decode($status, true); // echo date("Y-m-d H:i:s (").strlen($status)."):".print_r($data,true)."\n"; $this->stream->event()->setData(json_encode($data))->end()->flush(); } } //These are the application key and secret //You can create an application, and then get this info, from https://dev.twitter.com/apps //(They are under OAuth Settings, called "Consumer key" and "Consumer secret") define('TWITTER_CONSUMER_KEY', 'xcQK1Me1cJkzfFs1hRWtDexwM'); define('TWITTER_CONSUMER_SECRET', 'YojwnUVpuQQAlP4IFEHFjl0ZW0BZXmXdqx2E8YW0YOJKSEefYU'); //These are the user's token and secret //You can get this from https://dev.twitter.com/apps, under the "Your access token" //section for your app. define('OAUTH_TOKEN', '1058717184-VyQz2tjlt8kegThlEZdQqOXwmt9NkWoljQwa8Rx'); define('OAUTH_SECRET', 'FX3v5uHkntanSjWueMF41PAUkTTzMoMqdHlhp6HKAqhaV'); use Igorw\EventSource\Stream; foreach (Stream::getHeaders() as $name => $value) { header("{$name}: {$value}"); } // Start streaming $sc = new MyUserConsumer(OAUTH_TOKEN, OAUTH_SECRET, new Stream()); $sc->consume();
/** * @covers Igorw\EventSource\Stream::__construct * @covers Igorw\EventSource\Stream::getHeaders */ public function testGetHeaders() { $headers = Stream::getHeaders(); $this->assertInternalType('array', $headers); $this->assertSame('text/event-stream', $headers['Content-Type']); }
<?php use Igorw\EventSource\Stream; require __DIR__ . '/vendor/autoload.php'; set_time_limit(0); $redis = new Predis\Client(); $pubsub = $redis->pubSubLoop(); $pubsub->subscribe('notification'); foreach (Stream::getHeaders() as $name => $value) { header("{$name}: {$value}"); } $stream = new Stream(); foreach ($pubsub as $message) { if ('message' === $message->kind) { $stream->event()->setEvent($message->channel)->setData($message->payload)->end()->flush(); } }
/** * Output Event Stream Headers * * @return void */ public function outputStreamHeaders() { foreach (Stream::getHeaders() as $name => $value) { header("{$name}: {$value}"); } }