[SOLVED] - Getting error with fopen on locahost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

[SOLVED] - Getting error with fopen on locahost

Post by RobertGonzalez »

Can someone help me out on this?

I am using a snippet of code from Sitepoint that opens up their RSS feed file and parse the XML into something readable. I have the file in the test folder of my local development machine and am calling the files using http://localhost/test/readsitepoint.php.

My problem is that the call to fopen returns the following error:
Stupid PHP Error wrote:Warning: fopen(http://www.sitepoint.com/rss.php): failed to open stream: Bad file descriptor in c:\program files\apache group\apache\htdocs\test\readsitepoint.php on line 59
Here is the calling code...

Code: Select all

<?php
$fp = fopen("http://www.sitepoint.com/rss.php","r")
	or die("Error reading RSS data.");
?>
I have checked my php.ini file for allow_url_fopen and found it to be...

Code: Select all

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
allow_url_fopen = On
When I save the XML feed to a local file and fopen it from a local folder, it opens fine and does what it is supposed to do. But for some reason my localhost PHP won't open a file given a full URL. I tried this with the DevNet feed and got the same error.

As always, any help would be appreciated.
Last edited by RobertGonzalez on Wed Jun 07, 2006 9:11 pm, edited 1 time in total.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

i think that if you used fsockopen this might work.
PHP Website wrote:
fsockopen -- Open Internet or Unix domain socket connection
Description
resource fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )

Initiates a socket connection to the resource specified by target. PHP supports targets in the Internet and Unix domains as described in Appendix O. A list of supported transports can also be retrieved using stream_get_transports().
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I actually tried opening a socket and it farted even worse with that. Thanks for the suggestion though.
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

ok,well your welcome ( kinda did not know what i was talking about) but i thought since it was a remote file,it might need socket connection.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Yeah, I thought that might help too. I found a small snippet in the user comments of the manual, but that little piece of code didn't do anything. I am wondering if my company firewall could prevent my localhost server from accessing a remote page with fopen somehow?
User avatar
a94060
Forum Regular
Posts: 543
Joined: Fri Feb 10, 2006 4:53 pm

Post by a94060 »

that could be it maybe. You might want to try and connect to a local server( if you are in the same builiding/network as your server) try connecting to it and see what happens.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I should have said proxy server, not firewall (though the proxy does have a firewall). I think this may be the problem. There was another user comment in the manual that mentioned something like this. I will look into it from home to see if I can do it there.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

OK, it was a proxy server thing. So can anyone tell me why a proxy server would kill a connection to a URL through a script? I am totally ignorant when it comes to things like that so any information would be most useful and appreciated. Thanks.
Post Reply