Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return true if the given function has been defined
<?php function_exists(string $function): bool
<?php \fclose($this->master);
$errno = \defined('SOCKET_ENOTSOCK') ? \SOCKET_ENOTSOCK : 88;
$errstr = \function_exists('socket_strerror') ? \socket_strerror($errno) : 'Not a socket';
throw new \RuntimeException(
'Failed to listen on FD ' . $fd . ': ' . $errstr . ' (ENOTSOCK)',
<?php \fclose($this->master);
$errno = \defined('SOCKET_EISCONN') ? \SOCKET_EISCONN : 106;
$errstr = \function_exists('socket_strerror') ? \socket_strerror($errno) : 'Socket is connected';
throw new \RuntimeException(
'Failed to listen on FD ' . $fd . ': ' . $errstr . ' (EISCONN)',
<?php public function connect($uri)
{
if (!\function_exists('stream_socket_enable_crypto')) {
return Promise\reject(new \BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)')); // @codeCoverageIgnore
}
<?php public function __construct(ServerInterface $tcp, LoopInterface $loop = null, array $context = array())
{
if (!\function_exists('stream_socket_enable_crypto')) {
throw new \BadMethodCallException('Encryption not supported on your platform (HHVM < 3.8?)'); // @codeCoverageIgnore
}
<?php public static function errno($errstr)
{
if (\function_exists('socket_strerror')) {
foreach (\get_defined_constants(false) as $name => $value) {
if (\strpos($name, 'SOCKET_E') === 0 && \socket_strerror($value) === $errstr) {
return $value;
<?php public static function errconst($errno)
{
if (\function_exists('socket_strerror')) {
foreach (\get_defined_constants(false) as $name => $value) {
if ($value === $errno && \strpos($name, 'SOCKET_E') === 0) {
return ' (' . \substr($name, 7) . ')';
<?php if (false === \stream_socket_get_name($stream, true)) {
if (\function_exists('socket_import_stream')) {
$socket = \socket_import_stream($stream);
$errno = \socket_get_option($socket, \SOL_SOCKET, \SO_ERROR);
<?php $this->setExpectedException(
'RuntimeException',
'Failed to listen on FD ' . $fd . ': ' . (function_exists('socket_strerror') ? socket_strerror(SOCKET_EBADF) . ' (EBADF)' : 'Bad file descriptor'),
defined('SOCKET_EBADF') ? SOCKET_EBADF : 9
);
new FdServer($fd, $loop);
<?php $this->setExpectedException(
'RuntimeException',
'Failed to listen on FD ' . $fd . ': ' . (function_exists('socket_strerror') ? socket_strerror(SOCKET_ENOTSOCK) : 'Not a socket') . ' (ENOTSOCK)',
defined('SOCKET_ENOTSOCK') ? SOCKET_ENOTSOCK : 88
);
new FdServer($fd, $loop);
<?php $this->setExpectedException(
'RuntimeException',
'Failed to listen on FD ' . $fd . ': ' . (function_exists('socket_strerror') ? socket_strerror(SOCKET_EISCONN) : 'Socket is connected') . ' (EISCONN)',
defined('SOCKET_EISCONN') ? SOCKET_EISCONN : 106
);
new FdServer($fd, $loop);
<?php $this->setExpectedException(
'RuntimeException',
'Connection to tcp://127.0.0.1:9999 failed: Connection refused' . (function_exists('socket_import_stream') ? ' (ECONNREFUSED)' : ''),
defined('SOCKET_ECONNREFUSED') ? SOCKET_ECONNREFUSED : 111
);
Block\await($promise, null, self::TIMEOUT);
<?php public function connectionToInvalidNetworkShouldFailWithUnreachableError()
{
if (PHP_OS !== 'Linux' && !function_exists('socket_import_stream')) {
$this->markTestSkipped('Test requires either Linux or ext-sockets on PHP 5.4+');
}
<?php $this->setExpectedException(
'RuntimeException',
'Connection to ' . $address . ' failed: ' . (function_exists('socket_strerror') ? socket_strerror($enetunreach) . ' (ENETUNREACH)' : 'Network is unreachable'),
$enetunreach
);
<?php $this->setExpectedException(
'RuntimeException',
'Failed to listen on "tcp://127.0.0.1:' . $this->port . '": ' . (function_exists('socket_strerror') ? socket_strerror(SOCKET_EADDRINUSE) . ' (EADDRINUSE)' : 'Address already in use'),
defined('SOCKET_EADDRINUSE') ? SOCKET_EADDRINUSE : 0
);
new TcpServer($this->port);