From: [EMAIL PROTECTED] Operating system: RedHat Linux PHP version: 4.0.6 PHP Bug Type: Sockets related Bug description: Garbage being returned when displaying contents of a url
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 -- Edit bug report at: http://bugs.php.net/?id=14872&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]