|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-11 20:29 UTC] jim_ivers at americantours dot com
-Status: Open
+Status: Closed
[2010-08-11 20:29 UTC] jim_ivers at americantours dot com
[2010-08-12 08:27 UTC] mike@php.net
-Status: Closed
+Status: Bogus
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 15:00:01 2025 UTC |
Description: ------------ I have a php script running on apache that reads a string from a TCP socket on a server. Using the below script on a local server works. I cannot get it to return more than 1305 bytes remotely. The remote server reports sending the whole string (about 4K bytes) back. The following is a short version of the code below: while(($sting = socket_read($socket, $slen, PHP_BINARY_READ)) !== false) { $out = $out.$sting; if(strlen($out) >= $slen) break; } I get a warning that the socket closed, then the string: <b>Warning</b>: socket_read() [<a href='function.socket-read'>function.socket-read</a>]: unable to read from socket [104]: Connection reset by peer in <b>/usr/local/apache2/htdocs/mikidel.php</b> on line <b>473</b><br /> "returnstringabcdefg....." using php 5.3.3 w Apache/2.2.14 (Unix) PHP/5.3.3 on Centos 5 ( redhat clone) ./configure --enable-xml --enable-dom --with-openssl --enable-sockets --enable-debug --with-config-file-path=/etc --with-curl --with-zlib --enable-ftp --enable-soap --with-sybase-ct=/sybase --with-libxml-dir=/usr --prefix=/usr/local/apache2/php --with-config-file-path=/usr/local/apache/php --with-gettext --with-apxs2=/usr/local/apache2/bin/apxs php.ini standard vanilla note that the remote socket is C code, and I have tried using write(socket...) and send(socket...). Both work locally since there are no \n or \r. Neither work remotely. Test script: --------------- // Create a TCP/IP Socket $socket = socket_create (AF_INET, SOCK_STREAM, 0); if ($socket < 0) { echo "socket() failed: reason: " . strerror ($socket) . "\n"; } // Connect to Target $result = socket_connect ($socket, $address, $service_port); if ($result < 0) { echo "connect() failed.\nReason: ($result) " . strerror($result) . "\n"; } $tmp = socket_read ($socket, 6, PHP_BINARY_READ); $slen = (int)($tmp-6); $out = (string)$tmp; $sting = socket_read($socket, $slen, PHP_BINARY_READ); $out = $out.$sting; while(($sting = socket_read($socket, $slen, PHP_BINARY_READ)) !== false) { $out = $out.$sting; if(strlen($out) >= $slen) break; } // Close Socket socket_close ($socket); return $out."\n"; Expected result: ---------------- The script should work remotely since it works locally. Obviously if I ask for 4k bytes from a remote socket, it should return 4k bytes, since it does so from a local socket. Actual result: -------------- <b>Warning</b>: socket_read() [<a href='function.socket-read'>function.socket-read</a>]: unable to read from socket [104]: Connection reset by peer in <b>/usr/local/apache2/htdocs/mikidel.php</b> on line <b>473</b><br /> "returnstringabcdefg....."