Page 1 of 1

[SOLVED] - Getting error with fopen on locahost

Posted: Wed Jun 07, 2006 3:20 pm
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.

Posted: Wed Jun 07, 2006 3:28 pm
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().

Posted: Wed Jun 07, 2006 3:29 pm
by RobertGonzalez
I actually tried opening a socket and it farted even worse with that. Thanks for the suggestion though.

Posted: Wed Jun 07, 2006 3:31 pm
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.

Posted: Wed Jun 07, 2006 3:35 pm
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?

Posted: Wed Jun 07, 2006 3:46 pm
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.

Posted: Wed Jun 07, 2006 3:48 pm
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.

Posted: Wed Jun 07, 2006 9:10 pm
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.