# stream_socket_server() and timeout

- Thread: https://externals.io/message/57663
- Original archive: https://news-web.php.net/php.internals/57663
- Started by Alok Menghrajani on 2012-02-03T17:52:54+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #57663 — Alok Menghrajani — 2012-02-03T17:52:54+00:00

URL: https://externals.io/message/57663#57663

Hi,

PHP fails to set the socket_last_error when `stream_socket_server()` times
out.

It is therefore impossible to tell if a timeout occurred or if the call
failed for some other reason.

Here is a simple piece of that should help understand this issue:

<?php
// Call something that will set `socket_last_error()`
socket_create(AF_INET, SOCK_STREAM, 666);

$err = `socket_last_error()`;
echo 'before: ', socket_strerror($err), "\t", $err, "\n";

// now call stream_socket_accept and timeout
$sock = stream_socket_server('tcp://0.0.0.0:0 <http://0.0.0.0:0>');
$client = stream_socket_accept($sock, 1);

$err = `socket_last_error()`;
echo 'after: ', socket_strerror($err), "\t", $err, "\n";


PHP currently outputs:
before: Protocol not supported	43
after: Protocol not supported	43



I have a patch to fix this issue: http://pastebin.com/6JLjZkNu

The output then becomes:
before: Protocol not supported	43
after: Operation timed out	60

However the patch adds #include "ext/sockets/php_sockets.h" to
ext/standard/streamsfuncs.c. Is that something we are okay living with?


Thanks,
Alok
