经测试代码如下:
<?PHP
/**
* 请求github api 客户端
*
* @param
* @arrange (512.笔记) jb51.cc
**/
// 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();
/*** 来自:编程之家 jb51.cc(jb51.cc) ***/
?>
原文链接:https://www.f2er.com/php/528758.html