Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\Http\Client->getpeername(): array|false
None
Returns an array of a connected peer, showing its host and port that is being used by the socket.
Get the IP address and port of the remote server.
<?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->getpeername());
$client->close();
});