guzzle - How to process (Inserting in db) incoming streaming data in php?
379
I am continuously getting streaming twitter data from gnip by guzzle library in json formate.
Below is my code
require_once('vendor/autoload.php');
$url =https://stream.gnip.com:443/accounts/{account_name}/publishers/twitter/streams/track/dev.json";
$username = '*****';
$password = '*****';
$headers = array('Accept-Encoding' => 'gzip');
$client = new GuzzleHttp\Client();
$client->setDefaultOption('headers/Accept-Encoding', 'gzip');
$data = $client->get($url, ['auth' => [$username, $password]]))
{
$tdata = $data->getBody();
//here i am getting json data continuously,that I have to insert in my db.
//I have written my code to insert in db and it is inserting in db but after some time it will not insert in db.
}
So please suggest me ,if there are other best method or some php library available.
Answer
Solution:
For best practice, you can implement a rest service for inserting data in db. Let say you have a rest service;
You will send each streamed data to that service like;
When you get stream data, just run this function, and do not care about how to insert data in db. Maybe, you can handle data insertion part in service side.