Forum Moderators: coopster

Message Too Old, No Replies

file get contents + non existing URL's

never fails

         

macdar

3:08 pm on May 16, 2007 (gmt 0)

10+ Year Member



Hi,

not sure if that's the right forum, cuz it may have something to do with my apache configuration.

anyways, when I try to check if a given url exists with the file_get_conntents function, it always returns true.
I checked it, and when a page can not be found then it grabs my index page.

it never says:
Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Name or service not known in

Can you help?

thanks.

dreamcatcher

5:29 pm on May 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi macdar,

Try using file_exists [php.net] instead. If you are checking a server url on another server, fopen [php.net] will work fine.

dc

macdar

8:30 am on May 17, 2007 (gmt 0)

10+ Year Member



DC,

thanks for the tip.

Tried that and it turns out these functions behave in the same way.

Looks like all wrapper functions (fopen,fsockopen, file_get_contents etc..) do the same -when they can not reach a given URL, they bounce back to the domain they are called from, for example:

if I call the script from www.mydomain.com/script.php
(where in script.php: fopen ("http://non-existing-url.com", "r");)

and then it grabs content from www.mydomain.com, and thus it always returns true.

I had the same situation on my old box a while ago and my noc fixed it, but since I moved to a self-managed dedicated server I'm not sure what to do.

I think that's apache configuration - but not sure.

DC: if that's not php configuration case (allow_url_open set to ON), would you please move the post to the "apache" group?

thanks.

dreamcatcher

8:37 am on May 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you try it like this:

$fp = @fopen('http://www.example.com', "r");

if (!$fp)
{
echo 'Url doesn`t exist';
}

dc

macdar

8:54 am on May 17, 2007 (gmt 0)

10+ Year Member



yes, I did.

if www.example.com is a non-existing URL, then it grabs content from my site - and it's always true.

macdar

6:37 pm on May 17, 2007 (gmt 0)

10+ Year Member



any ideas anyone?

DC, do you think the "apache" group more appropriate to this problem?

Drag_Racer

7:18 pm on May 17, 2007 (gmt 0)

10+ Year Member



Your wording sounds like you only tried it against your own domain. If that be the case I would suggest you have an improper 404 setup on your server. It is redirecting instead of proper headers...

macdar

8:33 am on May 20, 2007 (gmt 0)

10+ Year Member



that may be the right direction, however I'm not sure if that's a 404 problem.. I mean if I request an non-existing file on my domain- the 404 pops up just fine..

I'm running Ubuntu Dapper with apache2 and php5 installed from packages.

any ideas?

macdar

9:22 am on May 22, 2007 (gmt 0)

10+ Year Member



can't believe no-one has met this problem before..

jatar_k

12:43 pm on May 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



after testing I can't reproduce this behaviour so I can only guess that it is specific to something in your setup.

I tried it with a couple different domains

whoisgregg

1:15 pm on May 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When file_get_contents hits a 404, it should throw a warning:

Warning: file_get_contents(http://www.example.com/somerandomnonsense.txt) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/file-get-contents-error.php on line 5

And the variable will be empty. You've definitely got some server configuration issue.

macdar

2:57 pm on May 23, 2007 (gmt 0)

10+ Year Member



yes, that's the expected behaviour. I tested it on my local machine (also running ubuntu, but apache has been installed from sources), and it prints out this kind of warning. it looks like the default apache configuration coming out of packages (which is on my server) still requires some tweaks.

I wonder if I should just install apache from sources. But I deliberately sticked with those packages, cuz I heard they are really tuned to that distro.

macdar

1:56 pm on May 27, 2007 (gmt 0)

10+ Year Member



I think I should have mentioned that I'm running wildcards for that domain (the one that is being fetched one the non-existing one is being called.)

also,

when I ping anything it resolves to that domain:

#root ping ddd
PING ddd.mydomain.com (11.22.33.44) 56(84) bytes of data.
64 bytes from mydomain.com (11.22.33.44): icmp_seq=1 ttl=64 time=0.022 ms
64 bytes from mydomain.com (11.22.33.44): icmp_seq=2 ttl=64 time=0.026 ms

macdar

2:43 pm on May 29, 2007 (gmt 0)

10+ Year Member



problem solved!

I was missing the following entry in the /etc/resolv.conf file:

search localhost

... :)

jatar_k

3:04 pm on May 29, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



glad you found, was driving me a bit nuts wondering