Skip to content

Instantly share code, notes, and snippets.

@igorw
Created August 19, 2012 21:55
Show Gist options
  • Save igorw/3398005 to your computer and use it in GitHub Desktop.
Save igorw/3398005 to your computer and use it in GitHub Desktop.
<?php
// http client making a request to github api
require __DIR__.'/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$client = new React\Http\Client($loop);
$request = $client->request('GET', 'https://api.github.com/repos/react-php/react/commits');
$request->on('response', function ($response) {
$buffer = '';
$response->on('data', function ($data) use (&$buffer) {
$buffer .= $data;
echo ".";
});
$response->on('end', function () use (&$buffer) {
$decoded = json_decode($buffer, true);
$latest = $decoded[0]['commit'];
$author = $latest['author']['name'];
$date = date('F j, Y', strtotime($latest['author']['date']));
echo "\n";
echo "Latest commit on react was done by {$author} on {$date}\n";
echo "{$latest['message']}\n";
});
});
$request->end();
$loop->run();
@cordoval
Copy link

@igorw, how to actually harvest the echos into a say variable string? ob_start and stuff? thought there was a better way if one wants to persist it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment