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

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

Declaration

<?php OpenSwoole\Coroutine\Http2\Client::__construct(string $host, int $port, bool $openSSL = false): OpenSwoole\Coroutine\Http2\Client

Parameters

host

IP address of the remote host. You can also specify a full domain name here if needed.

port

The port number of the remote host you want to connect to.

openSSL

If you want to enable support for SSL or not. Default is false.

Return

When successful it will return a OpenSwoole\Coroutine\Http2\Client object.


Description

The constructor for creating a new OpenSwoole\Coroutine\Http2\Client object.

If you need to set a timeout refer to the overall timeout guide.

When using SSL you must have installed OpenSwoole with the --enable-openssl flag and have OpenSSL installed on your server.


Example

<?php

use OpenSwoole\Coroutine\Http2\Client;

co::run(function()
{
    $client = new OpenSwoole\Coroutine\Http2\Client('127.0.0.1', 9518);

    var_dump($client);
});

The above creation of the HTTP2 client will have these class properties:

<?php

object(OpenSwoole\Coroutine\Http2\Client)#3 (9) {
  ["errCode"]=>
  int(0)
  ["errMsg"]=>
  int(0)
  ["sock"]=>
  int(-1)
  ["type"]=>
  int(0)
  ["setting"]=>
  NULL
  ["connected"]=>
  bool(false)
  ["host"]=>
  string(9) "127.0.0.1"
  ["port"]=>
  int(9518)
  ["ssl"]=>
  bool(false)
}
Last updated on September 1, 2022