socket_strerror

Supported Versions: PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8
Return a string describing a socket error
<?php socket_strerror(int $error_code): string
<?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     {

        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                         $socket = \socket_import_stream($stream);

                        $errno = \socket_get_option($socket, \SOL_SOCKET, \SO_ERROR);

                        $errstr = \socket_strerror($errno);

                    } elseif (\PHP_OS === 'Linux') {
<?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     public function testEmitsTimeoutErrorWhenAcceptListenerFails(\RuntimeException $exception)

    {

        $this->assertEquals('Unable to accept new connection: ' . socket_strerror(SOCKET_ETIMEDOUT) . ' (ETIMEDOUT)', $exception->getMessage());

        $this->assertEquals(SOCKET_ETIMEDOUT, $exception->getCode());

    }
<?php         $this->setExpectedException(

            'RuntimeException',

            'Connection to ' . $address . ' failed: ' . (function_exists('socket_strerror') ? socket_strerror($enetunreach) . ' (ENETUNREACH)' : 'Network is unreachable'),

            $enetunreach

        );
<?php             $this->markTestSkipped('Not supported on HHVM');

        }



        $this->assertEquals('Unable to accept new connection: ' . socket_strerror(SOCKET_ETIMEDOUT) . ' (ETIMEDOUT)', $exception->getMessage());

        $this->assertEquals(SOCKET_ETIMEDOUT, $exception->getCode());

    }
<?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);
<?php             $this->markTestSkipped('not supported on HHVM');

        }



        $this->assertEquals('Unable to accept new connection: ' . socket_strerror(SOCKET_ETIMEDOUT) . ' (ETIMEDOUT)', $exception->getMessage());

        $this->assertEquals(SOCKET_ETIMEDOUT, $exception->getCode());

    }