NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
nusoap - EOF reached before processing content-length bytes


Joined: 15 Nov 2009
Posts: 2
Location: Chicago, IL USA
Reply with quote
NuSoap experts,

I'm moving my website, powered by PHP, from a Linux server to a Windows Server 2008 server. My website uses nusoap for XML web services. One of my scripts which run perfectly on the linux server, is failing on the windows server. On the windows server, the nusoap is failing to receive all data. For example, if 29,778 is expected from the SOAP server, only 6,729 bytes are being received by the client on the windows server before EOF. The feof() function call in nusoap getResponse() (around line number 2656) is detecting EOF prematurely before reading all the data. If I add a "usleep(250000)" after each "fread()" in nusoap.php getResponse() as shown below, all data is received as expected. I've added some debugging and determined that the feof() which is returning true is the feof in the while loop on line 2655 of nusoap.php in getResponse().


The following is the debug info for nusoap 0.7.2 (actually is google's nusoap for php5 - 0.9). Note the content-length and the length of data actually read on the socket before EOF.
...
2009-11-15 11:12:49.194406 soapclientNusoap: transporting via HTTP
2009-11-15 11:12:49.197422 soapclientNusoap: sending message, length=904
2009-11-15 11:12:49.194785 soap_transport_http: scheme = http
2009-11-15 11:12:49.195125 soap_transport_http: host = toywebservices.com
2009-11-15 11:12:49.195435 soap_transport_http: path = /toywebservice/toywebservice.asmx
2009-11-15 11:12:49.195755 soap_transport_http: query = WSDL
2009-11-15 11:12:49.196101 soap_transport_http: set Host: toywebservices.com
2009-11-15 11:12:49.196447 soap_transport_http: set User-Agent: NuSOAP/0.7.2 (1.94)
2009-11-15 11:12:49.196784 soap_transport_http: set Content-Type: text/xml; charset=UTF-8
2009-11-15 11:12:49.197104 soap_transport_http: set SOAPAction: "http://toywebservices.com/toywebservice/GetToys"
2009-11-15 11:12:49.197770 soap_transport_http: entered send() soapclientsoap with data of length: 904
2009-11-15 11:12:49.198106 soap_transport_http: connect connection_timeout 0, response_timeout 30, scheme http, host toywebservices.com, port 80
2009-11-15 11:12:49.198420 soap_transport_http: calling fsockopen with host toywebservices.com connection_timeout 0
2009-11-15 11:12:49.248629 soap_transport_http: set response timeout to 30
2009-11-15 11:12:49.249045 soap_transport_http: socket connected
2009-11-15 11:12:49.249386 soap_transport_http: set Content-Length: 904
2009-11-15 11:12:49.249723 soap_transport_http: HTTP request: POST /toywebservice/toywebservice.asmx?WSDL HTTP/1.0
2009-11-15 11:12:49.250047 soap_transport_http: HTTP header: Host: toywebservices.com
2009-11-15 11:12:49.250644 soap_transport_http: HTTP header: User-Agent: NuSOAP/0.7.2 (1.94)
2009-11-15 11:12:49.250870 soap_transport_http: HTTP header: Content-Type: text/xml; charset=UTF-8
2009-11-15 11:12:49.251095 soap_transport_http: HTTP header: SOAPAction: "http://toywebservices.com/toywebservice/GetToys"
2009-11-15 11:12:49.251322 soap_transport_http: HTTP header: Content-Length: 904
2009-11-15 11:12:49.251600 soap_transport_http: wrote data to socket, length = 1178
2009-11-15 11:12:49.495428 soap_transport_http: read line of 17 bytes: HTTP/1.1 200 OK
2009-11-15 11:12:49.496245 soap_transport_http: read line of 19 bytes: Connection: close
2009-11-15 11:12:49.496577 soap_transport_http: read line of 37 bytes: Date: Sun, 15 Nov 2009 17:12:48 GMT
2009-11-15 11:12:49.496896 soap_transport_http: read line of 27 bytes: Server: Microsoft-IIS/6.0
2009-11-15 11:12:49.497215 soap_transport_http: read line of 23 bytes: X-Powered-By: ASP.NET
2009-11-15 11:12:49.497531 soap_transport_http: read line of 29 bytes: X-AspNet-Version: 2.0.50727
2009-11-15 11:12:49.497860 soap_transport_http: read line of 35 bytes: Cache-Control: private, max-age=0
2009-11-15 11:12:49.498177 soap_transport_http: read line of 39 bytes: Content-Type: text/xml; charset=utf-8
2009-11-15 11:12:49.498494 soap_transport_http: read line of 23 bytes: Content-Length: 29778
2009-11-15 11:12:49.498825 soap_transport_http: read line of 2 bytes:
2009-11-15 11:12:49.499211 soap_transport_http: found end of headers after length 251
2009-11-15 11:12:49.499648 soap_transport_http: want to read content of length 29778 <<<<<<<<<<<<<< Data received 29,778 B
2009-11-15 11:12:49.500080 soap_transport_http: read buffer of 3969 bytes
2009-11-15 11:12:49.550862 soap_transport_http: read buffer of 2760 bytes
2009-11-15 11:12:49.551665 soap_transport_http: read to EOF
2009-11-15 11:12:49.551984 soap_transport_http: read body of length 6729 <<<<<<<<<<<<<< data read much less than 29,778 B
2009-11-15 11:12:49.552329 soap_transport_http: received a total of 6980 bytes of data from server
2009-11-15 11:12:49.552910 soap_transport_http: closed socket
2009-11-15 11:12:49.553266 soap_transport_http: No Content-Encoding header
2009-11-15 11:12:49.553603 soap_transport_http: end of send()
2009-11-15 11:12:49.553950 soapclientNusoap: got response, length=6729 type=text/xml; charset=utf-8
2009-11-15 11:12:49.554268 soapclientNusoap: Entering parseResponse() for data of length 6729 and type text/xml; charset=utf-8
2009-11-15 11:12:49.554619 soapclientNusoap: Got response encoding: utf-8
2009-11-15 11:12:49.555015 soapclientNusoap: Use encoding: UTF-8 when creating soap_parser
2009-11-15 11:12:49.555648 soap_parser: Charset from HTTP Content-Type matches encoding from XML declaration
2009-11-15 11:12:49.555967 soap_parser: Entering soap_parser(), length=6729, encoding=UTF-8
2009-11-15 11:12:49.556838 soap_parser: found root struct GetToysResponse, pos 2
..
2009-11-15 11:12:49.592188 soap_parser: XML error parsing SOAP payload on line 1: Invalid document end
2009-11-15 11:12:49.592534 soap_parser: XML payload:...
...
2009-11-15 11:12:49.593503 soapclientNusoap: Error: XML error parsing SOAP payload on line 1: Invalid document end
</pre>





nusoap.php getResponse()
....
..
while (($strlen < $content_length) && (!feof($this->fp))) {
echo "<br><br>loop count $loopCount";
echo "<br> top strlen $strlen";

$readlen = min(8192, $content_length - $strlen);
$tmp = fread($this->fp, $readlen);
$tmplen = strlen($tmp);
$this->debug("read buffer of $tmplen bytes");
usleep(250000); # <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$this->debug("$tmp");


if (($tmplen == 0) && (!feof($this->fp))) {
$this->incoming_payload = $data;
$this->debug('socket read of body timed out after length ' . strlen($data));
$this->debug("read before timeout:\n" . $data);
$this->setError('socket read of body timed out');
return false;
}
$strlen += $tmplen;
$data .= $tmp;

....


Here's the successful result when the usleep is added:

2009-11-15 11:30:03.923987 soapclientNusoap: transporting via HTTP
2009-11-15 11:30:03.927135 soapclientNusoap: sending message, length=904
2009-11-15 11:30:03.924362 soap_transport_http: scheme = http
2009-11-15 11:30:03.924740 soap_transport_http: host = toywebservices.com
2009-11-15 11:30:03.925052 soap_transport_http: path = /toywebservice/toywebservice.asmx
2009-11-15 11:30:03.925363 soap_transport_http: query = WSDL
2009-11-15 11:30:03.925771 soap_transport_http: set Host: toywebservices.com
2009-11-15 11:30:03.926142 soap_transport_http: set User-Agent: NuSOAP/0.7.2 (1.94)
2009-11-15 11:30:03.926469 soap_transport_http: set Content-Type: text/xml; charset=UTF-8
2009-11-15 11:30:03.926817 soap_transport_http: set SOAPAction: &quot;http://toywebservices.com/toywebservice/GetToys&quot;
2009-11-15 11:30:03.927473 soap_transport_http: entered send() soapclientsoap with data of length: 904
2009-11-15 11:30:03.927840 soap_transport_http: connect connection_timeout 0, response_timeout 30, scheme http, host toywebservices.com, port 80
2009-11-15 11:30:03.928155 soap_transport_http: calling fsockopen with host toywebservices.com connection_timeout 0
2009-11-15 11:30:03.972269 soap_transport_http: set response timeout to 30
2009-11-15 11:30:03.972654 soap_transport_http: socket connected
2009-11-15 11:30:03.972983 soap_transport_http: set Content-Length: 904
2009-11-15 11:30:03.973304 soap_transport_http: HTTP request: POST /toywebservice/toywebservice.asmx?WSDL HTTP/1.0
2009-11-15 11:30:03.973642 soap_transport_http: HTTP header: Host: toywebservices.com
2009-11-15 11:30:03.973962 soap_transport_http: HTTP header: User-Agent: NuSOAP/0.7.2 (1.94)
2009-11-15 11:30:03.974281 soap_transport_http: HTTP header: Content-Type: text/xml; charset=UTF-8
2009-11-15 11:30:03.974611 soap_transport_http: HTTP header: SOAPAction: &quot;http://toywebservices.com/toywebservice/GetToys&quot;
2009-11-15 11:30:03.974930 soap_transport_http: HTTP header: Content-Length: 904
2009-11-15 11:30:03.975299 soap_transport_http: wrote data to socket, length = 1178
2009-11-15 11:30:04.384516 soap_transport_http: read line of 17 bytes: HTTP/1.1 200 OK
2009-11-15 11:30:04.384917 soap_transport_http: read line of 19 bytes: Connection: close
2009-11-15 11:30:04.385237 soap_transport_http: read line of 37 bytes: Date: Sun, 15 Nov 2009 17:30:03 GMT
2009-11-15 11:30:04.385955 soap_transport_http: read line of 27 bytes: Server: Microsoft-IIS/6.0
2009-11-15 11:30:04.386273 soap_transport_http: read line of 23 bytes: X-Powered-By: ASP.NET
2009-11-15 11:30:04.386593 soap_transport_http: read line of 29 bytes: X-AspNet-Version: 2.0.50727
2009-11-15 11:30:04.386975 soap_transport_http: read line of 35 bytes: Cache-Control: private, max-age=0
2009-11-15 11:30:04.387428 soap_transport_http: read line of 39 bytes: Content-Type: text/xml; charset=utf-8
2009-11-15 11:30:04.387896 soap_transport_http: read line of 23 bytes: Content-Length: 29778
2009-11-15 11:30:04.388216 soap_transport_http: read line of 2 bytes:
2009-11-15 11:30:04.388597 soap_transport_http: found end of headers after length 251
2009-11-15 11:30:04.389030 soap_transport_http: want to read content of length 29778 <<<<<<<<<<<<< Data is 29.778 Bytes
2009-11-15 11:30:04.389484 soap_transport_http: read buffer of 8192 bytes
2009-11-15 11:30:04.629347 soap_transport_http: read buffer of 8192 bytes
2009-11-15 11:30:04.879362 soap_transport_http: read buffer of 8192 bytes
2009-11-15 11:30:05.129402 soap_transport_http: read buffer of 5202 bytes
2009-11-15 11:30:05.379715 soap_transport_http: read to EOF
2009-11-15 11:30:05.380081 soap_transport_http: read body of length 29778 <<<<<<<<<<<<< Read all 29.778 Bytes
2009-11-15 11:30:05.380486 soap_transport_http: received a total of 30029 bytes of data from server
2009-11-15 11:30:05.380933 soap_transport_http: closed socket
2009-11-15 11:30:05.381278 soap_transport_http: No Content-Encoding header
2009-11-15 11:30:05.381613 soap_transport_http: end of send()
2009-11-15 11:30:05.381998 soapclientNusoap: got response, length=29778 type=text/xml; charset=utf-8
2009-11-15 11:30:05.382317 soapclientNusoap: Entering parseResponse() for data of length 29778 and type text/xml; charset=utf-8
2009-11-15 11:30:05.382654 soapclientNusoap: Got response encoding: utf-8
2009-11-15 11:30:05.383051 soapclientNusoap: Use encoding: UTF-8 when creating soap_parser
2009-11-15 11:30:05.383689 soap_parser: Charset from HTTP Content-Type matches encoding from XML declaration
2009-11-15 11:30:05.384006 soap_parser: Entering soap_parser(), length=29778, encoding=UTF-8
2009-11-15 11:30:05.384975 soap_parser: found root struct GetToysResponse, pos 2
...
..
2009-11-15 11:30:05.543380 soap_parser: in buildVal, adding Java Vector GetToysResponse
2009-11-15 11:30:05.543746 soap_parser: parsed successfully, found root struct: 2 of name GetToysResponse
2009-11-15 11:30:05.546637 soapclientNusoap: sent message successfully and got a(n) array
return=array(1) {
..
...


Does anyone know the fix for this issue? I could leave the usleep in place, I'm just afraid that this is just a hack and not a valid fix.

Thanks,
Jassen
View user's profileFind all posts by jassenSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I think the problem is in feof() which is not properly ported to Windows platform.
Try the latest version of PHP and if the problem is still there, report bugs at http://bugs.php.net
Please note, that you'll have to write a _SIMPLE_ sample demonstrating the problem. I don't think nusoap is acceptable, but you can easily extract nusoap http transport class and demonistrate its work against any public http server.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 15 Nov 2009
Posts: 2
Location: Chicago, IL USA
Reply with quote
Thanks for the response Dmitri. I am experiencing this problem with nusoap-for-php5 and PHP 5.2.11.

Due to this problem I've already started porting my scripts from nusoap to PHP 5 SOAP. I am now experiencing another differnt issue for which I've raised a PHP bug report: http://bugs.php.net/bug.php?id=50298.
View user's profileFind all posts by jassenSend private message


Joined: 03 Apr 2012
Posts: 1
Reply with quote
jassen wrote:
Thanks for the response Dmitri. I am experiencing this problem with nusoap-for-php5 and PHP 5.2.11.

Due to this problem I've already started porting my scripts from nusoap to PHP 5 SOAP. I am now experiencing another differnt issue for which I've raised a PHP bug report: http://bugs.php.net/bug.php?id=50298.

We experienced exactly the same problem with PHP 5.2.11. The usleep() call did not helpded. We moved to PHP 5.2.17 and it solved the problem (even with an old nusoap library version). The problem was definitively in PHP fread() function.
View user's profileFind all posts by studio26Send private message
nusoap - EOF reached before processing content-length bytes
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic