tags:

views:

700

answers:

5

any idea why fopen would timeout for a file if it is on my server and I know the url is correct?

update: sorry, i should have mentioned this is in php. the code is:

fopen($url, 'r');

It works if i put in a relative path for the file, but not if $url is a url in my server (but it works for google.com). Thanks for the help.

Alaitnik's answer was right. The problem only appears when i access my own server files through the ethernet interface. How can I fix this? I need to be able to access the file from the ethernet interface because the url loads dynamically (it's generated from a wordpress cms, so the url doesn't technically exist as a file on my server)

+2  A: 

Hi,

you can use ini_set('default_socket_timeout',2); before opening the fopen $url . This actually set the default socket connection timout without responding. Stream_set_timeout sets time out on the stream that is established via fopn or socket opening functions. Try this may be helpful for you.

x4tje
A: 

If you are trying to get the HTML of a URL, I suggest using curl instead of fopen.

fopen is best used with local files, coz it does not "know" how to deal with the idiosyncrasies of a network resource.

Here Be Wolves
A: 

Check the comments on the documentation of fopen. There's a whole lot of gold in there.

rojoca
+1  A: 

It appears that you're trying to download a file from your own server using the HTTP protocol from a program running on that same server?

If so, the timeout problem is likely to be web server or network configuration related. Timeouts normally only happen because either:

  1. the server really is taking a long time to send back the answer, or
  2. the TCP connection is being blocked

For example, it may be that your local firewall rules only permit access to www.example.com if those queries come from the ethernet interface, but a locally made connection would try to go via the loopback interface.

Alnitak
Wow, you're right. How can I fix this? I need to be able to access the file from the ethernet interface because the url loads dynamically (it's generated from a wordpress cms, so the url doesn't technically exist as a file on my server)
To fix this we need to know more about what exactly is blocking the traffic. What happens if you ask for the same file but with localhost in the URL instead of the hostname? If that doesn't work because of name-based virtual hosting, put the website's name in the hosts file on address 127.0.0.1
Alnitak
+1  A: 

maybe your "allow_url_fopen" is set to "Off" check your php.ini file or phpinfo()

hayato