note 52552 added to function.socket-recv
| From: | php-general at lists dot php dot net | Date: | Thu, 05 May 2005 14:42:43 +0000 |
| Subject: | note 52552 added to function.socket-recv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88964@lists.php.net to get a copy of this message | ||
I'm glad that Bastion left the above post about the mysterious int flag. He just helped to fix
a problem that I've spent six hours on. Here's my code:
for($ct=1; $ct<=$numrecs; $ct++) {
$rec = "";
$nr=socket_recv($fp,$rec,77,0);
print "Rec # $ct -->";
print "$rec";
print "<br>";
}
The code is pretty simple, it just loops through all my records and prints them out. All records are
77 bytes and all end with a period. The first 36 records print perfectly then at 37 things go bad.
The records start to get offset. The last few characters of the 37th record end up printing on the
38th record. The data on the sending side was perfect, so I knew that the problem was with
socked_recv.
After reading the above post I tried changing the int flag. Changing the flag to 2 worked:
$nr=socket_recv($fp,$rec,77,2);
Now everything lines up perfectly. I had always left int flag as 0 since it's undocumented.
Martin K.
----
Manual Page -- http://www.php.net/manual/en/function.socket-recv.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52552
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52552&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52552&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52552&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52552&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52552&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52552&report=yes
Search -- http://master.php.net/manage/user-notes.php