php 请求github api 客户端的简单示例

前端之家收集整理的这篇文章主要介绍了php 请求github api 客户端的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

<?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

猜你在找的PHP相关文章