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

Declaration

<?php
Swoole\Coroutine\Http2\Client::__construct(string $host, int $port, bool $openSSL = false): Swoole\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 Swoole\Coroutine\Http2\Client object.


Description

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

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

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


Example

<?php

use Swoole\Coroutine\Http2\Client;

Co\run(function()
{
    $client = new Swoole\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(Swoole\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)
}