Swoole Coroutine HTTP Client

Swoole\Coroutine\HTTP2\Client

Coroutine HTTP2 Client.

Example:

<?php
use Swoole\Coroutine as co;

co::create(function ()
{
    $cli = new co\Http2\Client('127.0.0.1', 9518);
    $cli->set([ 'timeout' => 1]);
    $cli->connect();

    $req = new co\Http2\Request;
    $req->path = "/index.html";
    $req->headers = [
        'host' => "localhost",
        "user-agent" => 'Chrome/49.0.2587.3',
        'accept' => 'text/html,application/xhtml+xml,application/xml',
        'accept-encoding' => 'gzip',
    ];
    $req->cookies = ['name' => 'rango', 'email' => '1234@qq.com'];
    var_dump($cli->send($req));
    $resp = $cli->recv();
    var_dump($resp);

});
Swoole\Coroutine\HTTP2\Client->set(array $options)

Set the variables of the client: timeout.

Swoole\Coroutine\Http2\Client->connect()

Connect to the remote server.

Swoole\Coroutine\Http2\Client->send(swoole_http2_request $request) : int | false

Send request to the remote server.

Swoole\Coroutine\Http2\Client->write(int $streamId, mixed $data, bool $end = false)

Write data to the remote server.

Example:

<?php
use Swoole\Coroutine as co;

co::create(function () use ($fp)
{
    $cli = new co\Http2\Client('127.0.0.1', 9518);
    $cli->set([ 'timeout' => 1]);
    var_dump($cli->connect());

    $req3 = new co\Http2\Request;
    $req3->path = "/index.php";
    $req3->headers = [
        'host' => "localhost",
        "user-agent" => 'Chrome/49.0.2587.3',
        'accept' => 'text/html,application/xhtml+xml,application/xml',
        'accept-encoding' => 'gzip',
    ];
    $req3->pipeline = true;
    $req3->method = "POST";
    $streamId = $cli->send($req3);
    $cli->write($streamId, ['int' => rand(1000, 9999)]);
    $cli->write($streamId, ['int' => rand(1000, 9999)]);
    //end stream
    $cli->write($streamId, ['int' => rand(1000, 9999), 'end' => true], true);
    var_dump($cli->recv());
    $cli->close();
});
Swoole\Coroutine\Http2\Client->recv(float $timeout) : Http2\Response

Receive data from the remote server.

Swoole\Coroutine\Http2\Client->close();

Close the connection.