Swoole\Coroutine\Http\Client->getsockname()

Notice: ext-swoole is supported until v4.7.1, use ext-openswoole >= v4.7.1. Latest version: pecl install openswoole-4.10.0

Declaration

<?php
Swoole\Coroutine\Http\Client->getsockname(): array|false

Parameters

None

Return

Returns an array, showing its host and port that is being used by the socket.


Description

Get the local IP address and port of the HTTP client.


Example

<?php
use Swoole\Coroutine\HTTP\Client;

Co\run(function() 
{
    $client = new Client('127.0.0.1', 80);

    $client->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);

    $client->set(['timeout' => 1]);

    $client->setDefer(true);

    $client->get('/index.php');

    var_dump($cli->getsockname());

    $client->close();
});