|  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.
Bug Type:
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:

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

if(!$fp) {
  echo "$errstr ($errno)<br>\n";
} else {
  while(!feof($fp)) {

    if(ereg($START_CONT,$line)) {
    if(ereg($END_CONT,$line)) $content=0;
    if($content==1)echo $line;

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

Useful Links:
Full text of script with problem:
Full test of script which works:

See working solution (click "printer-friendly version"):
See problem (click "printer-friendly version"):



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-05 09:55 UTC]
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,
 [2002-01-05 11:59 UTC]
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

Thanks for the clarification.

I posted this question in a number of forums, including, devsheds, phpbuilder, htmlforums, 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-2022 The PHP Group
All rights reserved.
Last updated: Fri Jul 01 14:05:46 2022 UTC