php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14872 Garbage being returned when displaying contents of a url
Submitted: 2002-01-05 09:14 UTC Modified: 2002-01-05 15:18 UTC
From: webmaster at ski-info-online dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.0.6 OS: RedHat Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: webmaster at ski-info-online dot com
New email:
PHP Version: OS:

 

 [2002-01-05 09:14 UTC] webmaster at ski-info-online dot com
What should happen:
==================
The script is meant to create a printer-friendly version of a ski resort review page that is produced dynamically. It does this by opening a socket connection to the url, including the query, and read the contents of that url line by line looking for <!-- START CONTENTS --> and <!-- END CONTENTS --> tags. It echoes whatever is between those tags.

What does happen:
================
The script works except for two issues.
1) In between some of the paragraphs of text some garbage hex numbers appear. They are always in the same place and the first two bytes are always the same.
2) The script runs extremely slowly which is attributed completely to the fsockopen() function.

It should be noted that by simply replacing the fsockopen with fopen() the problems disappeared without any other changes to the code.

Extraction from the Script that fails:
=====================================
<?
<snip>
$fp=fsockopen($myServer,80,&$errno,&$errstr,30);

$request = "GET $document"."?"."$query"." HTTP/1.1\r\n";
$request .= "Host: $myServer\r\n\r\n";

if(!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  fputs($fp,$request);
  $content=0;
  $in_title=0;
?>
</snip>
<snip>
<?
  while(!feof($fp)) {
    $line=fgets($fp,4096);

    if(ereg($START_CONT,$line)) {
        $content=1;
    }
    if(ereg($END_CONT,$line)) $content=0;
    if($content==1)echo $line;
}
fclose($fp);
?>

Extraction from working script:
==============================
<snip>
<?
$fp=fopen($myURL,r); //in place of fsockopen()
// $request lines no longer required, removed.
?>
</snip>

Useful Links:
============
Full text of script with problem:
www.ski-info-online.com/php-report/print-fails.txt
Full test of script which works:
www.ski-info-online.com/php-report/print-works.txt

See working solution (click "printer-friendly version"):
www.ski-info-online.com/skiResort-print1.php?id=Alpbach
See problem (click "printer-friendly version"):
www.ski-info-online.com/skiResort-fail.php?id=Alpbach

Thanks
Torrent

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-05 09:55 UTC] hholzgra@php.net
i don't know about the performance loss
but the hex numbers you get are just what
you requested

by sending a HTTP/1.1 request you have
declared that you are willing to 'speak'
HTTP/1.1, and the HTTP/1.1 RFC 2616, 
Section 3.6 defines:

[...]
All HTTP/1.1 applications MUST be able to receive 
and decode the "chunked" transfer-coding,
[...]

http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6
 [2002-01-05 11:59 UTC] hholzgra@php.net
Steve Meyers wrote:

  The performance loss is also due to using HTTP/1.1, 
  which defaults to having keepalive on. 
  Until you tell it to close the connection or it times 
  out (about 2 seconds), it will keep it open.
 
  Switching to HTTP/1.0 fixes both issues.

status changed to bogus as both issues
where related to misunderstanding of HTTP
concepts and not at all a PHP problem
 [2002-01-05 15:18 UTC] webmaster at ski-info-online dot com
Steve,

Thanks for the clarification.

I posted this question in a number of forums, including, devsheds, phpbuilder, htmlforums, php-general@lists.php.net and it would appear that many of us do not understand the intricacies of HTTP 1.1 and HTTP 1.0 as no one appeared to be able to identify the cause.

Apologies if this request wasted your time.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 06:01:29 2024 UTC