Skip to content

Stream Socket Timeout #11175

Closed
ThePHPF/thephp.foundation
#90
@mohamedallou

Description

@mohamedallou

Description

The following code:

<?php
$socket = stream_socket_server("tcp://0.0.0.0:8080", $errno, $errstr);
if (!$socket) {
    echo "$errstr ($errno)<br />\n";
} else {
    while ($conn = stream_socket_accept($socket, -1)) {
        fwrite($conn, 'The local time is ' . date('n/j/Y g:i a') . "\n");
        fclose($conn);
    }
    fclose($socket);
}

Resulted in this output:

Warning: stream_socket_accept(): Accept failed: Operation timed out in ....server.php

But I expected this output instead:

The expected behaviour until php ** 8.1** is to make this function wait indefinitely to incoming connections, just as in socket_accept, by setting the timeout to -1. But it times out immediately

The setting of default_socket_timeout to a negative value via init_set does not fix the problem as well.

PHP Version

PHP 8.2.5

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions