PHP fopen timeout?

any idea why fopen will timeout for a file if it's on my server and i know the url is correct?

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

fopen($url, 'r');

      

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

The answer to Alaytnik's question was right. The problem only occurs when accessing my own server files over ethernet interface. How can I fix this? I need to be able to access the file from the ethernet interface because the url is loaded dynamically (it is generated from wordpress cms, so the url does not technically exist as a file on my server)
0


a source to share


6 answers


you can use ini_set ('default_socket_timeout', 2); before opening fopen $ url. This actually set the default connection timeout with no response. Stream_set_timeout sets the stream timeout, which is set via fopn or opening a socket. Try it may be helpful to you.



+4


a source


You seem to be trying to download a file from your own server using the HTTP protocol from a program running on the same server?

If so, the timeout issue is likely related to your webserver or network setup. Waiting times usually only happen because:



  • the server does take a long time to send a response, or
  • blocked TCP connection

For example, it could be that your local firewall rules only allow access www.example.com

if those requests are coming from the ethernet interface, but the local connection will try to go through the loopback interface.

+3


a source


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

+1


a source


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

fopen is best used with local files because it doesn't "know" how to handle the specifics of a network resource.

0


a source


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

0


a source


It took me a while to solve this problem, but here I found it thanks to Alnitak. Opening the file with the localhost in the url instead of the hostname was a trick for me.

0


a source







All Articles