Bug #52571 [Csd->Bgs]: socket_read function returns max 1305 bytes remote, OK local
| From: | mike@php.net | Date: | Thu, 12 Aug 2010 06:27:38 +0000 |
| Subject: | Bug #52571 [Csd->Bgs]: socket_read function returns max 1305 bytes remote, OK local | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-153355@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52571&edit=1
ID: 52571
Updated by: mike@php.net
Reported by: jim_ivers at americantours dot com
Summary: socket_read function returns max 1305 bytes remote,
OK local
-Status: Closed
+Status: Bogus
Type: Bug
Package: Streams related
Operating System: Centos 5 (redhat clone)
PHP Version: 5.3.3
Block user comment: N
Previous Comments:
------------------------------------------------------------------------
[2010-08-11 20:29:25] jim_ivers at americantours dot com
To clarify, the socket server is remote or local, the php code is always
local.
Turns out one of the libraries on the remote server is using unicode, 4
bytes to the character. Thus the string it is trying to return is 4
times as long as the string length.
------------------------------------------------------------------------
[2010-08-09 22:45:00] jim_ivers at americantours dot com
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 this bug report at http://bugs.php.net/bug.php?id=52571&edit=1