PHP Classes

truncated response

Recommend this page to a friend!

      PHP HTTP protocol client  >  All threads  >  truncated response  >  (Un) Subscribe thread alerts  
Subject:truncated response
Summary:response truncated at 8K
Messages:5
Author:Junkie Narkosvin
Date:2010-12-07 03:08:28
Update:2011-01-27 02:31:34
 

 


  1. truncated response   Reply   Report abuse  
Picture of Junkie Narkosvin Junkie Narkosvin - 2010-12-07 03:08:28
Thank you for this otherwise extremely useful class, but I've run into a rather strange problem - the response is truncated at 8K, and I can't seem to read the remainder of the response.

For example:

$c = new http_class;
$c->timeout = 15;
$c->data_timeout = 15;
$c->debug = 0;
$c->file_buffer_length = 1024*1024;

$c->GetRequestArguments($url, $args);
$c->Open($args);
$c->SendRequest($args);
$c->ReadReplyBody($body, 1024*1024);

I left out the error checking just to demonstrate the problem.

The response comes back truncated at 8K, even though I've set both the file_buffer_length, and a large size when calling ReadReplyBody().

Any clues?

  2. Re: truncated response   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-12-07 04:22:29 - In reply to message 1 from Junkie Narkosvin
The ReadReplyBody second parameter is not the length you want to read but rather the limit of bytes that will be returned.

You need to keep calling the ReadReplyBody until the body parameter is empty.

  3. Re: truncated response   Reply   Report abuse  
Picture of Junkie Narkosvin Junkie Narkosvin - 2010-12-07 19:35:53 - In reply to message 2 from Manuel Lemos
I guess what's missing for me is some way to read the entire respose - in my case, I'm going to parse the returned HTML document, so reading a partial response really isn't that useful.

I would suggest adding a method similar to this one:

Function ReadFullReplyBody(&$body)
{
$buffer = '_';
$body = '';
$error = '';
while ($buffer != '')
{
$error = $this->ReadReplyBody($buffer, $this->file_buffer_length);
if ($error !='')
return $error;
$body .= $buffer;
}
return $error;
}

I added this method to my own copy of the script, and it worked as expected.

Hope this contribution is useful :-)

Thanks again!

  4. Re: truncated response   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2010-12-08 07:31:18 - In reply to message 3 from Junkie Narkosvin
OK, I may add it in a future release. Thanks for the suggestion.

  5. Re: truncated response   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2011-01-27 02:31:34 - In reply to message 3 from Junkie Narkosvin
I just uploaded a new version with the function ReadWholeReplyBody that reads the whole reply body at once. Thanks for the suggestion.