-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Stream Socket Timeout #11175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I cannot reproduce that on linux nor windows, can you provide a bit more information about operating system and if this script is executed in console or from http (fpm, apache)? |
This was tested on MacOs X php 8.2.5 in a console script. The timeout does not happen if we use positive numbers, .i.e if we set 5 seconds it will time out after 5 second if there are no request. This works correctly. The only problem was with negative value -1 which times out immediately. |
On the other side, if we replicate this logic using the socket api: socket_create. socket_listen... Everything works fine. |
M1 or Intel? I cannot test that further unfortunately. |
I used M1, Mac OS 13.0 and php 8.2.5 |
I have a strong feeling this is due to the undefined behaviour issue in #11177. Because when UB happens the compiler is allowed to generate any code it, i.e. the -1 situation "does not happen" according to the compiler. |
…viour A negative value like -1 may overflow and cause incorrect results in the timeout variable, which causes an immediate timeout. As this is caused by undefined behaviour the exact behaviour depends on the compiler, its version, and the platform. A large overflow is also possible, if an extremely large timeout value is passed we also set an indefinite timeout. This is because the timeout value is at least a 64-bit number and waiting for UINT64_MAX/1000000 seconds is waiting about 584K years.
Description
The following code:
Resulted in this output:
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
The text was updated successfully, but these errors were encountered: