php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #35449 stream_socket_recvfrom() docs don't mention about it's buffer bypassing
Submitted: 2005-11-28 15:30 UTC Modified: 2005-12-06 16:02 UTC
From: profic at kursknet dot ru Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [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.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-29 14:26 UTC] vrana@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-12-03 15:37 UTC] profic at kursknet dot ru
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.
 [2005-12-04 16:29 UTC] nlopess@php.net
Well, the recvfrom() function is supposed to be used with connection-less sockets (such as UDP), not TCP.
Anyway PHP is smart enough to call recv when needed. But it will read the data directly from the socket and not from the usual stream buffer (checked with Wez & source code).
This should be documented, of course.
 [2005-12-04 19:20 UTC] profic at kursknet dot ru
Well, but example in current documentation use tcp :).
That's how I understand that it is bypass stream buffer - look to sources, and about documenting this behaviour was my bug report.
 [2005-12-06 16:02 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Calls to stream_socket_recvfrom() on socket-based streams, after calls to buffer-based stream functions (like fread() or steam_get_line()) read data directly from the socket and bypass the stream buffer."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Sep 11 09:00:01 2025 UTC