HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

socket_last_error

Description

The socket_last_error of Sockets for PHP returns the last error on the socket.

Syntax

socket_last_error(
    ?Socket $socket = null
): int

Parameters

socket

A Socket instance created with socket_create().

Return

Returns a socket error code.

Examples

1 · void

<?

$domain = AF_INET;
$type = SOCK_RDM;
$protocol = 0;

$socket = socket_create($domain, $type, $protocol);

    if($socket === false)
    {
        $return = socket_last_error();

        die("$return");
    }

socket_close($socket);
94

2 · socket

<?

$domain = AF_INET;
$type = SOCK_STREAM;
$protocol = SOL_TCP;

$socket = socket_create($domain, $type, $protocol);

    $address = '127.0.0.1';
    $port = 80;

    $socket_bind = socket_bind($socket, $address, $port);

    if($socket_bind === false)
    {
        $return = socket_last_error($socket);

        die("$return");
    }

socket_close($socket);
<!doctype html>
<html>
<head>
    <title>PHP</title>
    <style>
        html, a
        {
            background-color: rgb(255 0 255 / 0.1);
        }
        a
        {
            color: purple;
            transition-duration: 1s;

            &:hover
            {
                background-color: rgb(0 0 0 / 0.1);
                color: black;
                text-decoration-color: transparent;
            }
        }
    </style>
</head>
<body>
    <a href="/php/">PHP</a>
    <script>
        function myfunction(myparameter)
        {
            const mytarget = myparameter.target;
            const mystyle = mytarget.style;
            mystyle.position = "absolute";
            mystyle.left = `${Math.random() * (window.innerWidth - mytarget.offsetWidth)}px`;
            mystyle.top = `${Math.random() * (window.innerHeight - mytarget.offsetHeight)}px`;
        }
        document.querySelector("a").addEventListener("mouseout", myfunction);
    </script>
</body>
</html>