× 警告!旧版文档已经暂停维护,请查看新版文档。点击前往新版文档

Coroutine\Http2\Client

协程Http2客户端。

实例

go(function () {
    $domain = 'www.zhihu.com';
    $cli = new Swoole\Coroutine\Http2\Client($domain, 443, true);
    $cli->set([
        'timeout' => -1,
        'ssl_host_name' => $domain
    ]);
    $cli->connect();
    $req = new swoole_http2_request;
    $req->method = 'POST';
    $req->path = '/api/v4/answers/300000000/voters';
    $req->headers = [
        'host' => $domain,
        "user-agent" => 'Chrome/49.0.2587.3',
        'accept' => 'text/html,application/xhtml+xml,application/xml',
        'accept-encoding' => 'gzip'
    ];
    $req->data = '{"type":"up"}';
    $cli->send($req);
    $response = $cli->recv();
    assert(json_decode($response->data)->error->code === 602);
});

  • 13993995515

    WARNING swProtocol_recv_check_length: package is too big, remote_addr=unknown:0, length=4740189. 例子一直报错

  • 18656553691

    $cli->set([ 'timeout' => 5.000, 'ssl_host_name' => $domain, 'package_max_length' => 9000000, //协议最大长度 ]);

  • 数据过大,就算设置了package_max_length,还是无法接收到任何数据,直接返回false

  • nekocc

    给例子中的代码添加 package_max_length 之后可以正常运行…… 但是如果我去 get www.baidu.com / 的话就又会 package is too big …… 自己扩展了一下又各种 client is not connected to server ,得花很多时间找原因…… 话说协程这一块的文档写的真的……好乱,大部分情况都得结合 client 部分的文档去看,而且 async 那边的 http client 功能现在砍了文档又没更新……

  • 17721234896

    Uncaught Error: Class 'Swoole\Coroutine\Http2\Client' not found 怎么处理啊

  • 13521888752

    swoole4.3.3 版本, 提示 Uncaught Error: Class 'Swoole\Coroutine\Http2\Client' not found