On my Ubuntu 12.04 server running PHP 5.5 on Lighttpd I have
I am not sure this is right but I also put in extension=openssl.so in my php.ini file and rebooted by server. I see no untoward error messages in my logs.
Nevertheless I still get failed to open stream: Connection timed out. The same URL without https works just fine. Am I missing something
As someone said above this is a network issue. Actually, I was wrong when I said that http://exmaple.com worked whilst https://example.com did not. I run four servers, call them A, B, C & D at different global locations - two in the US, one in Europe and one in Asia. The URL that I am trying to reach is for another server in the US. After posting this question and reviewing the various comments I explored matters a bit more and discovered that my file_get_contents call was failing only from the Asian server. TraceRoute revealed that the Asian server is simply unable to locate the one I want to reach. So as someone here said - this is a network issue. I am posting this answer so anyone who runs into this thread in quest of a solution to a similar problem realizes that this might well be the problem rather than a PHP configuration thing.
There are a few possibilities, but you will be able to find out more about what the reason is if you just try to curl
the HTTPs URL from the command line of the server where the code is running.
curl -v https://url
Common problems would be that the https cert at url
is not valid, or that outgoing https connections are blocked on your server.