php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14578 socket_read() behavior
Submitted: 2001-12-18 08:35 UTC Modified: 2002-01-28 10:43 UTC
From: martin at humany dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.1.0 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
34 - 2 = ?
Subscribe to this entry?

 
 [2001-12-18 08:35 UTC] martin at humany dot com
I call socket_read() like this:

$data = socket_read($handle, 80, PHP_BINARY_READ);
and get 80 byte back. i made a loop to continue read until strlen($data) < 80 (just experimenting):
--
$cnt = 0;
do {
$row = socket_read($irc, 80, PHP_BINARY_READ);
$cnt .= strlen($row);
if (strlen($row) < 80) break;
}
echo "$cnt bytes read";
--
This gives me 1027 bytes of data, even though there is more data left to read, the last read only returns 67 bytes of data.

if i call socket_read() with 2048 as size, i also only get 1027 bytes back


So i worked around this in my example loop like this:


$cnt = 0;
do {
$row = socket_read($irc, 1028, PHP_BINARY_READ);
$cnt .= strlen($row);
if (strlen($row) < 1028) break;
}
echo "$cnt bytes read";


Wich works, and reads everything for me. But is this really the expected behaviour?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-18 08:37 UTC] martin at humany dot com
Hm in my last example there should be 
--
$cnt = 0;
do {
$row = socket_read($irc, 1027, PHP_BINARY_READ);
$cnt .= strlen($row);
if (strlen($row) < 1027) break;
}
echo "$cnt bytes read";
--

of course, not 1028 :)
 [2002-01-28 10:43 UTC] sterling@php.net
This is not a php issue, this is either a winsock or programmer issue.  The fact that socket_read() returns correctly, means that socket_read() is correct (cause all we do is map socket_read() to a recv() call).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 16:01:30 2024 UTC