php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22508 fopen() Problems
Submitted: 2003-03-02 16:25 UTC Modified: 2003-04-28 22:30 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jim at bluedojo dot com Assigned: wez (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 4.3.2 RC 1 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
16 + 23 = ?
Subscribe to this entry?

 
 [2003-03-02 16:25 UTC] jim at bluedojo dot com
The pages that is crashing my Apache server include, "http://www.sltrib2002.com". What is happening is fopen() is trying to open this link but the link redirects. When this link is placed in a browser, it actually redirects to, "http://www.sltrib2002.com/main/index.asp". This occurs in PHP 4.3.1.  When I downgraded to PHP 4.2.3 fopen() worked fine.

Here is more information about the problem in detail: 

I am running WinXP, Apache 1.3, MySQL 3.23, and PHP 4.3.1. 

I have a php page called "populate.php" that is using fopen() to index web pages. This works most of the time when I load this page in a browser, but fopen() is causing problems. Sometimes a specific web site (that has a redirecting link) causes Apache to crash. A window pops up saying, "Apache.exe has encountered a problem and needs to close. We are sorry for the inconvenience." And in the browser it says, "The page cannot be loaded." 

Although it says it crashes, the Apache server still seems to run if I load another page. It seems as if only that specific connection crashed. But this is the problem. I need to find out a way so it does not crash the page, populate.php, so it can continue running without getting the error in the browser "The page cannot be loaded." 

I tried the same web site on another configuration of Apache (that I pay for and am trying to avoid) and the page loads fine. Why is fopen crashing my server if the link redirects?  Again, this occured in PHP 4.3.1.  I had to downgrade for fopen to work ok with websites that redirect.


The code below will produce the error in PHP 4.3.1.

<?
        //The site http://www.vsacentral.com
        //redirects to
        //http://www.vsacentral.com/main.php
        //
        //Also try this
        //http://www.sltrib2002.com
        //It redirects to
        //http://www.sltrib2002.com/main/index.asp
	
        $url = "http://www.vsacentral.com";
	if ($fd = @fopen($url,"r"))
		echo "Success";
	else
		echo "Failure";
	
	fclose($fd);
		
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-02 16:47 UTC] wez@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-03-02 21:04 UTC] jim at bluedojo dot com
I also wanted to note that in version PHP 4.2.3 fopen will not work if it redirects from http:// to https://.  Perhaps it should return false in this case.
 [2003-03-03 03:22 UTC] wez@php.net
We are not fixing bugs in 4.2.x releases any longer; 4.3.x is the current stable branch, PHP 5 is the current development version.
 [2003-03-03 18:46 UTC] jim at bluedojo dot com
Hello wez, and thanks for the speedy updates on fopen().

I've found some more types of URLS that causes an error using fopen().  I'm using Apache 1.3 and PHP 4.3.x (I used the latest CVS version.)  They are listed below.

1.) If it redirects from http:// to https:// it will crash Apache connection.
Example Link: http://registration.ft.com/registration/sub/manageYourAccount.jsp

2.) If fopen() loads an unauthorized page -- HTTP Error 403 (Forbidden) it crashes Apache connection.
Example Link: http://www.fc-gabarron.es/en

3.) And I'm not sure why this is causing an error:
Example Link: http://www.sportingnews.com/RealMedia/ads/click_lx.ads/www.sportingnews.com/soccer/articles/20030302/460373.html/1065908018/Right3/default/empty.gif/34313165376634343365363238633430

I'm not to familiar with programming with sockets and HTTP protocol, but is there a way to catch all the errors and just simply return false if the connection doesn't open?

Just place the link in this code to see it happen:

<?	
        $url = "(url goes here)";
	if ($fd = @fopen($url,"r"))
		echo "Success";
	else
		echo "Failure";
	
	fclose($fd);
		
?>
 [2003-03-04 08:34 UTC] iliaa@php.net
1 & 2 seems to work fine in latest CVS.
#3 is a curios bugger, since it causes an unterminated loop due to what appears to the circular redirect against PHP has no protection.
 [2003-03-04 10:21 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2003-04-17 23:55 UTC] jim at bluedojo dot com
This code produces bug (memory leak?) in 4.3.2 RC 1  (Please excuse the porn link):

<?

	$url = "http://www.free-adult-anime-porn-cartoons.com/robots.txt";

	if ($fd = @fopen($url,"r"))
		echo "Success";
	else
		echo "Failure";
	
	fclose($fd);
		
?>
 [2003-04-18 00:24 UTC] jim at bluedojo dot com
Continuing from the above post I sent 5 minutes ago this link causes php.exe to crash too in 4.3.2 RC 1:

http://registration.ft.com/registration/sub/manageYourAccount.jsp
 [2003-04-18 12:51 UTC] jim at bluedojo dot com
For some reason, I submitted an error and it became closed so now I am re-opening it.  The message begins from 17 Apr 2003 concerning fopen crashing php.exe.

This code produces bug (memory leak?) in 4.3.2 RC 1  (Please excuse the
porn link):

<?

	$url = "http://www.free-adult-anime-porn-cartoons.com/robots.txt";

	if ($fd = @fopen($url,"r"))
		echo "Success";
	else
		echo "Failure";
	
	fclose($fd);
		
?>

This link also causes error: 

http://registration.ft.com/registration/sub/manageYourAccount.jsp
 [2003-04-28 22:30 UTC] jim at bluedojo dot com
The snapshot u gave me works for the fopen problems I mentioned.  It is very, very stable.  I also had other problems too but this one seemed to fix a lot of errors and memory leaks.  Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC