Forum Moderators: coopster

Message Too Old, No Replies

file() error

         

rjbearcan

9:45 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



Good afternoon everyone.

I have been using the file() function for quite some time without fail, until yesterday. I am getting an error when I use it as such:

$url = "http://www.example.com";
$data = implode('', file($url));

This is the error I'm getting:
Warning: file(http://www.example.com) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 999 in /filetest.php on line 3

I'm using it on a site that has other pages that work with the same code that's giving me errors now but for whatever reason, I'm getting this error and have no clue what it means. I'm also getting an implode() error but I know that is because the file() isn't working.

Any help would be greatly appreciated.

coopster

9:49 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Can you open the url in a browser?

eelixduppy

9:50 pm on Nov 7, 2007 (gmt 0)



Make sure that the url resolves to an actual page and then make sure that the allow_url_fopen directive is set to true in your php.ini configuration file. Other than that, it should work. It does seem a little excessive to be using file(), however; have you considered using file_get_contents [us2.php.net] and returning it as a string?

rjbearcan

10:19 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



I checked before, and again now, and yes, it does open to an actual page and both the local and master values for allow_url_fopen are on.

Whether I use file() or file_get_contents() it doesn't matter, both are giving me this error.

rjbearcan

10:36 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



If I try include I get this error:
Warning: main(http://www.example.com) [function.main]: failed to open stream: HTTP request failed! HTTP/1.1 999 in /filetest.php on line 2

Warning: main() [function.include]: Failed opening 'http://www.example.com' for inclusion (include_path='.:/usr/local/lib/php') in /filetest.php on line 2

Is this just me or is this weird?

whoisgregg

10:45 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would check to see if a different URL returns the same error. Try a URL on your own site if the one giving you trouble is from someone else's site. If the error is from your site, try a URL from a big popular site. Does it also fail? If so, does it get the same error?

rjbearcan

3:17 am on Nov 8, 2007 (gmt 0)

10+ Year Member



I have tried my own pages and I don't have a problem. I tried a large site and again, no problem. The site is not mine but when I try other pages (not the pages I want mind you) from this site, they work too.

Since I can't post the urls here I will send out a couple of SM's so you can see what I'm getting at.

Habtom

5:03 am on Nov 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This might be more of a configuration problem.

Look at the following thread: file get contents + non existing URL's [webmasterworld.com]

<edit> Reading back the post, this might not be the case </edit>

[edited by: Habtom at 5:05 am (utc) on Nov. 8, 2007]

coopster

11:58 pm on Nov 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It could be a firewall issue too. I couldn't find definitive answers, but here is a bug report that has some detail:

[bugs.php.net...]