Page 1 of 1

problem with fsockopen and stream_get_line

Posted: Fri Oct 16, 2009 11:16 am
by kage
ok my code is something like this

Code: Select all

function getpage($conn, $page)
{
   $fp = fsockopen($conn, 80, $errno, $errstr, 30);
   if (!$fp) {
      echo "$errstr ($errno)<br />\n";
   } else {
      $out = "GET ".$page." HTTP/1.1\r\n";
      $out .= "Host: ".$conn."\r\n";
      $out .= "Content-type: text/html\r\n"; 
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
 while (!feof($fp))
      {
         $buffer = stream_get_line($fp, 1024, "\n");
         echo $buffer;
      }
problem is it works great, but there is data in there that is not in the original source of the website it is looking at.

for example part of the original source looks like

Code: Select all

class="tBox">24

but when i look at it using the above function

Code: Select all

class="tB
C
ox">                        2
5FF4
4          
not exactly the same, it throws 5FF4's in a couple times a page, always in the same places. any ideas why?

thanks
kyle

Re: problem with fsockopen and stream_get_line

Posted: Fri Oct 16, 2009 12:43 pm
by John Cartwright
Is the HTTP response returned Chunked-Encoded? The extra data in there look like block sizes. Perhaps you should try libcurl in place, which supports chunked encoding.

Otherwise, try downgrading the HTTP protocol to 1.0.

Re: problem with fsockopen and stream_get_line

Posted: Fri Oct 16, 2009 2:20 pm
by kage
yes changing 1.1 to 1.0 worked perfectly, thanks