php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1455 Passing URL to fopen() sometimes gives bogus results.
Submitted: 1999-05-26 15:49 UTC Modified: 1999-06-18 11:53 UTC
From: vic at altoona dot net Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: Red Hat Linux 5.2
Private report: No CVE-ID: None
 [1999-05-26 15:49 UTC] vic at altoona dot net
Hi,

The following code often works, however, on some URLs it fails with the following strange error:
Warning: fopen("http://www.lysator.liu.se/mit-guide/mit-guide.html","r") - Success in /home/vic/public_html/mywall/bug.phtml on line 9
Even though it says success, it's acting like its timing out and the handle returned is null.
I can telnet to the server and issue a get command by hand and it works fine, so I am guessing that it is a problem
with PHP.  I haven't had time to look at the PHP source code but I thought I'd at least let you know about the problem.

If it matters, I am using this with Apache 1.3.6 and postgresql.

function GetTitle($url)
{
        $cnt=3;

        while (!($fp=fopen($url, "r")))
        {
                $cnt--;
                if (!$cnt)
                   break;
                sleep(5);
echo "Failed opening ".$url;
        }

        if ($fp)
        {
                $buf=fread($fp, 4096);

                if ($s=strpos(strtoupper($buf), "<TITLE>"))
                {
                        $s+=7;
                        $e=strpos(strtoupper($buf), "</TITLE>");
                        $title=trim(substr($buf, $s, $e-$s));
                }
                else
                {
                        $title="no title";
                }
                fclose($fp);
        }
        else
        {
                $title="WARNING: Couldn't open ".$url;
        }
        return($title);
}

echo GetTitle("http://www.lysator.liu.se/mit-guide/mit-guide.html");

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-18 11:53 UTC] sas at cvs dot php dot net
fixed in CVS
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 11:00:02 2026 UTC