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/ */
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);
}
}