go to bug id or search bugs for
stream_get_contents() with any maxlength greater than -1 returns an empty string,
This only appears to occur with UDP streams opened via stream_socket_client(), specifically on Windows 10.
This problem doesn't occur on Linux and may function fine on older versions of Windows.
The problem appears to reside somewhere in the php_stream_eof call within _php_stream_copy_to_mem - php_stream_eof seems to always return true on UDP streams on Windows 10 systems. More digging required.
//Submit DNS Request
$data = base64_decode("1oIBAAABAAAAAAAAB2V4YW1wbGUDb3JnAAABAAE=");
$fd = stream_socket_client("udp://18.104.22.168:53", $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);
var_dump(stream_get_contents($fd,65565)); //Does not work
var_dump(stream_get_contents($fd)); //No maxlength, works fine
Returns a valid DNS response roughly 45 bytes long, then an empty string.
Returns an empty string, then a valid DNS response.
Add a Patch
Add a Pull Request
Thanks for the report. I'm not reproducing this, here 7.0 through master
string(45) "ւ�� ☺ ☺ example♥org ☺ ☺�♀ ☺ ☺ J� ♦]��""
Either it's some environment issue, or indeed some more investigation is needed.
Ah, err, to few coffee in the morning. The exact actual result, so verified.
Btw. question - why don't you use stream_socket_recvfrom()? The reason to fail here is a possible bug in the stream liveness check, need further tests.
stream_socket_recvfrom() seems to work just fine in this case
I submitted this bug after tracking down a problem with reactphp's dns resolver which uses a generic socket class and tracked it down to this function not behaving correctly on Windows. I've already reported it to reactphp and offered a few workarounds, but figured I should still submit this report given this function behaves differently between *nix and Windows with maxlength set.
Automatic comment on behalf of ab
Log: Fixed bug #74090 stream_get_contents maxlength>-1 returns empty string