|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-28 15:30 UTC] profic at kursknet dot ru
Description: ------------ Calls to stream_socket_recvfrom() on socket-based streams, after calls to buffer-based stream funcions (like fread(), steam_get_line()) may lead to unexpected (to user) results as it is bypass stream buffer. Thus is seems to be a good idea to have warning/note in documentation of stream_socket_recvfrom() about this. Elsewise it can be runtime notice in case of use stream_socket_recvfrom() on stream with non-empty buffer. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 12:00:02 2025 UTC |
Hm. I didn't suppose, that documentashion problem needs test case. Here is one: <?php $s = stream_socket_client('tcp://localhost:80', $errno, $error, 5); stream_socket_sendto($s, "GET http://localhost/ HTTP/1.0\r\n"); stream_socket_sendto($s, "Host: localhost\r\n"); stream_socket_sendto($s, "\r\n"); echo "stream_get_line():\n"; var_dump(stream_get_line($s, 1500, "\r\n")); echo "stream_socket_recvfrom():\n"; var_dump(stream_socket_recvfrom($s, 100)); echo "stream_get_contents():\n"; var_dump(stream_get_contents($s, 100)); ?> Output of it for my system is: stream_get_line(): string(15) "HTTP/1.1 200 OK" stream_socket_recvfrom(): bool(false) stream_get_contents(): string(100) "Date: Sat, 03 Dec 2005 14:32:05 GMT Server: Apache/2.0.54 (Win32) PHP/5.1.0RC5-dev Content-Length:" As you can see stream_socket_recvfrom() returns false the same as when "end of socket" is reached. And it is reached. All incoming data from socket is stored in stream buffer, call to stream_get_contents() proves that.