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

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\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 OpenSwoole 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 OpenSwoole\Http2\Request;
use OpenSwoole\Coroutine\Http2\Client;

co::run(function()
{
    // Setup a new HTTP2 client and a timeout
    $client = new OpenSwoole\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 OpenSwoole\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 September 1, 2022