problem with fsockopen and stream_get_line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kage
Forum Newbie
Posts: 10
Joined: Thu Aug 07, 2003 11:34 am

problem with fsockopen and stream_get_line

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: problem with fsockopen and stream_get_line

Post 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.
kage
Forum Newbie
Posts: 10
Joined: Thu Aug 07, 2003 11:34 am

Re: problem with fsockopen and stream_get_line

Post by kage »

yes changing 1.1 to 1.0 worked perfectly, thanks
Post Reply