ID: 49759 Updated by: f...@php.net Reported By: chmod3 at googlemail dot com -Status: Open +Status: Feedback Bug Type: Sockets related Operating System: WinVista & FreeBSD PHP Version: 5.3.0 New Comment:
I think your example code makes no sense. When I change it a bit, it works as expected (Did you check PHP_BINARY READ vs. PHP_NORMAL_READ?) <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $connection = socket_connect($socket, 'news.giganews.com', 119); do { $recv = ''; echo "//START READ\n"; $recv = socket_read($socket, 1 ); var_dump($recv); echo "\\\\END READ\n\n"; } while($recv != '' && $recv !== false && $recv != "\n"); echo 'OUTPUT'; ?> I do agree that the docs could be clarified. Previous Comments: ------------------------------------------------------------------------ [2009-10-03 12:42:42] chmod3 at googlemail dot com Description: ------------ According to documentation: "Note: socket_read() returns a zero length string ("") when there is no more data to read." This does not seem to be the case on my installations: PHP 5.3.0 WinVista PHP 5.2.11 WinVista PHP 5.2.11 FreeBSD PHP 5.2.10 WinVista PHP 5.2.9 WinVista socket_read() just hangs. Reproduce code: --------------- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $connection = socket_connect($socket, 'news.giganews.com', 119); $response = ''; do { $recv = ''; echo "START READ\n"; $recv = socket_read($socket, 512); echo "END READ\n"; var_dump($recv); if($recv != '') { $response .= $recv; } } while($recv != ''); echo 'OUTPUT: ' . $reply; Expected result: ---------------- START READ END READ string(23) "200 News.GigaNews.Com " START READ END READ OUTPUT: 200 News.GigaNews.Com Actual result: -------------- START READ END READ string(23) "200 News.GigaNews.Com " START READ ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49759&edit=1