Swoole\Coroutine\Http2\Client->set(...)

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Coroutine\Http2\Client->set(array $options): void

Parameters

An array of options to set for the client, these options are specific to the object only. It should be a key-value array.

Return

None


Description

Set client specific options, see the overall options for Swoole clients.

You can change options throughout the use of the client if needed.


Example

See the use of the set() method below, create the client object and set options before use so changes take effect but it is possible to change options later. Any settings changed again will just overwrite previous values.

<?php

use Swoole\Http2\Request;
use Swoole\Coroutine\Http2\Client;

Co\run(function()
{
    // Setup a new HTTP2 client and a timeout
    $client = new Swoole\Coroutine\HTTP2\Client('127.0.0.1', 9518);

    // Set specific client options
    $client->set([
      'timeout' => 2,
      'open_eof_check' => true,
      'package_max_length' => 2000000,
    ]);

    // Try and connect to the remote host
    $client->connect();

    // Create and build a request that will be sent...
    $request = new Swoole\HTTP2\Request();
    $request->path = "/index.php";
    $request->headers = [
        'host' => "localhost",
        "user-agent" => 'Chrome/49.0.2587.3',
        'accept' => 'text/html,application/xhtml+xml,application/xml',
        'accept-encoding' => 'gzip',
    ];

    // Add cookies to the request
    $request->cookies = ['name' => 'hello', 'email' => '[email protected]'];

    // Send and receive a response and output the result
    var_dump($client->send($request));
    $response = $client->recv();
    var_dump($response);
});
Last updated on August 31, 2022