PHP code example of richweber / yii2-phirehose

1. Go to this page and download the library: Download richweber/yii2-phirehose library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

richweber / yii2-phirehose example snippets


'components' => [
    ...
    'stream' => [
        'class' => 'richweber\twitter\streaming\lib\Stream',
        'username' => '1111111111-pPylwxC33VekLORMEfBIqYq8qekK4SqiD8pQpTs',
        'password' => 'OpKLltXkXBIUd4RQLwY8slLg3iIo2BCpXlgvkqxEBn33X',
        'consumerKey' => 'rvyKdnYDN887ohIfQU8m7tnxy',
        'consumerSecret' => 'oCYPFJSRPVlelJhEUCGVE8Aps0s4GpEfvNFR1ESQ01xTcq0xYL',
        'method' => 'user',
        'format' => 'json',
    ],
    ...
],



namespace console\controllers;

use richweber\twitter\streaming\lib\Phirehose;

class StreamController extends \yii\console\Controller
{
    public function actionIndex()
    {
        Yii::$app->stream->consume();
    }
}



namespace common\components;

use richweber\twitter\streaming\lib\Stream;
use common\models\Twitts;

class MyStream extends Stream
{
    // This function is called automatically by the Phirehose class
    // when a new tweet is received with the JSON data in $status
    public function enqueueStatus($status)
    {
        $stream = json_decode($status);
        if (!(isset($stream->id_str))) { return; }

        $model = new Twitts;
        $model->tweet_id = $stream->id_str;
        $model->code = base64_encode(serialize($stream));
        $model->is_processed = 0;
        $model->created_at = time();
        $model->save();

        var_dump($stream);
    }
}

'components' => [
    ...
    'stream' => [
        'class' => 'common\components\MyStream',
        ...
    ],
    ...
],

$ php composer.phar 

php yii stream

nohup php yii stream > /dev/null 2>&1&