Coroutine HTTP2 Client

Coroutine HTTP2 Client.

Methods

  • Swoole\Coroutine\HTTP2\Client->__construct
  • Swoole\Coroutine\HTTP2\Client->set
  • Swoole\Coroutine\HTTP2\Client->connect
  • Swoole\Coroutine\HTTP2\Client->send
  • Swoole\Coroutine\HTTP2\Client->write
  • Swoole\Coroutine\HTTP2\Client->recv
  • Swoole\Coroutine\HTTP2\Client->read
  • Swoole\Coroutine\HTTP2\Client->close

    Example

    <?php
    
    Co\run(function () {
        $cli = new Swoole\Coroutine\HTTP2\Client('127.0.0.1', 9518);
        $cli->set([ 'timeout' => 1]);
        $cli->connect();
    
        $req = new Swoole\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' => 'hello', 'email' => '[email protected]'];
        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
    
    Co\run(function () use ($fp)
    {
        $cli = new Swoole\Coroutine\HTTP2\Client('127.0.0.1', 9518);
        $cli->set([ 'timeout' => 1]);
        var_dump($cli->connect());
    
        $req3 = new Swoole\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->read(float $timeout = -1) : HTTP2\Response

    Since version 4.5.0

    Read data from the remote server more than once.

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

    Close the connection.