From:
Operating system: Centos 5 (redhat clone)
PHP version: 5.3.3
Package: Streams related
Bug Type: Bug
Bug description:socket_read function returns max 1305 bytes remote, OK local
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....."
--
Edit bug report at http://bugs.php.net/bug.php?id=52571&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=52571&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=52571&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=52571&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=52571&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=52571&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=52571&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=52571&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=52571&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=52571&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=52571&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=52571&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=52571&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=52571&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=52571&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52571&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=52571&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=52571&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=52571&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=52571&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=52571&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=52571&r=mysqlcfg