Supported Versions: PHP 5, PHP 7, PHP 8
Retrieve the name of the local or remote sockets
<?php stream_socket_get_name(resource $socket, bool $remote): string|false
<?php return null;
}
return $this->parseAddress(\stream_socket_get_name($this->stream, true));
}
public function getLocalAddress()
<?php return null;
}
return $this->parseAddress(\stream_socket_get_name($this->stream, false));
}
private function parseAddress($address)
<?php if (\stream_socket_get_name($this->master, true) !== false) {
\fclose($this->master);
$errno = \defined('SOCKET_EISCONN') ? \SOCKET_EISCONN : 106;
<?php return null;
}
$address = \stream_socket_get_name($this->master, false);
if ($this->unix === true) {
return 'unix://' . $address;
<?php if (false === \stream_socket_get_name($stream, true)) {
if (\function_exists('socket_import_stream')) {
<?php return null;
}
$address = \stream_socket_get_name($this->master, false);
$pos = \strrpos($address, ':');
<?php return null;
}
return 'unix://' . \stream_socket_get_name($this->master, false);
}
public function pause()
<?php $socket = stream_socket_server('tcp://127.0.0.1:0');
$fd = self::getNextFreeFd();
$client = stream_socket_client('tcp://' . stream_socket_get_name($socket, false));
assert($client !== false);
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
<?php $server = new FdServer($fd, $loop);
$this->assertEquals('tcp://' . stream_socket_get_name($socket, false), $server->getAddress());
}
public function testGetAddressReturnsSameAddressAsOriginalSocketForIpv4SocketGivenAsUrlToFd()
<?php $server = new FdServer('php://fd/' . $fd, $loop);
$this->assertEquals('tcp://' . stream_socket_get_name($socket, false), $server->getAddress());
}
public function testGetAddressReturnsSameAddressAsOriginalSocketForIpv6Socket()
<?php $server = new FdServer($fd, $loop);
$port = preg_replace('/.*:/', '', stream_socket_get_name($socket, false));
$this->assertEquals('tcp://[::1]:' . $port, $server->getAddress());
}
<?php $server = new FdServer($fd, $loop);
$this->assertEquals('unix://' . stream_socket_get_name($socket, false), $server->getAddress());
}
public function testGetAddressReturnsNullAfterClose()
<?php $socket = stream_socket_server('127.0.0.1:0');
assert($socket !== false);
$client = stream_socket_client('tcp://' . stream_socket_get_name($socket, false));
$server = new FdServer($fd);
$promise = new Promise(function ($resolve) use ($server) {
<?php $socket = stream_socket_server('udp://127.0.0.1:0', $errno, $errstr, STREAM_SERVER_BIND);
$connector = new Connector(array(
'dns' => 'udp://' . stream_socket_get_name($socket, false),
'happy_eyeballs' => false
));
<?php $server = new SocketServer('php://fd/' . $fd);
$server->pause();
$this->assertEquals('tcp://' . stream_socket_get_name($socket, false), $server->getAddress());
}
public function testEmitsErrorWhenUnderlyingTcpServerEmitsError()