5
I asked that question here, but hardly, because it is a problem that seems to be specific, the solution would be something that would be something generic.
But it occurred to me in this question I asked is that I’m having problems with the function file_get_contents
.
When I make a request through it, always an error is returned:
file_get_contents('https://getcomposer.org/versions')
The return is:
PHP warning: file_get_contents(https://getcomposer.org/versions): failed to open stream: Connection timed out on line 1
However, when I open this url in the browser, everything works perfectly. What’s more, if I try to request the url https://www.google.com
the same problem occurs.
But the strange thing is that it’s not all the urls that generate this problem.
If I do this, it works:
file_get_contents('/')
I thought at first the problem was with the https
urls, but that doesn’t seem to be it.
If I use the curl
works, but I don’t want to use it, because I depend exclusively on the file_get_contents
on that occasion.
What can do with what the file_get_contents
gives timeout error on some specific urls, and they normally open from the browser?
Observing: I wouldn’t like answers like "using the Curl as an alternative solution, "since I really need to use file_get_contents to that end (in addition, a response with
curl
would not answer my question).
Here the
file_get_contents
no problem. Make aCURL
.– Diego Souza
Dude, I told you. Look at
max_execution_time
. And another parameter too:default_socket_timeout
.– Diego Souza
As for your specific example
echo file_get_contents('https://getcomposer.org/versions');
works well here and with google the same thing, but I’m looking for some service where this error occurs to see if I can answer your question– Miguel
Damn it, I figured out what the problem is, the answer might hold for the two questions, kkkkkk
– Wallace Maxters
Aff, I found nothing!
– Wallace Maxters
Where are you trying to use this code? If possible share the snippet of the code that is giving this problem.
– Carlos Fernandes
@Carlosfernandes independent of the stretch, happens this.
– Wallace Maxters
This problem is occurring on the local or remote server?
– Carlos Fernandes
I’m using in Local, on the command line.
– Wallace Maxters
Emulate a virtual machine and try to use the
file_get_contents
. From what I read here, there is a great possibility of being a problem in the network or in the configuration of PHP.– Carlos Fernandes