views:

129

answers:

1

file_get_contents() is returning "failed to open stream" when I call it on an HTTPS URL.

Warning: file_get_contents(https://google.com) [function.file-get-contents]: failed to open stream: No error in E:\\htdocs\callback3.php on line 5

Same call will work with a non-SSL URL.

At first, I thought it was a security issue with my webhoster, but I have verified with phpinfo() that allow url open is indeed allowed. I have also tried this code and verified it works:

Anyone have any ideas why file_get_contents() is failing with an HTTPS URL?

update: People correctly pointed out this was an HTTPS issue. My webhoster claims this should work, and has no idea how to resolve this. Anyone have specific directions I can give them for their IIS7 setup?

+2  A: 

That is probably because they are using the secure protocol https. This is strange though, in their examples, facebook is giving the similar example.

Sarfraz
+1, PHP needs to have SSL compiled in for SSL to work. Although, on my dev-server the lack of SSL gave an error of `failed to open stream: Invalid argument ` with `file_get_contents`. But double check your PHPinfo output for SSL support.
nikc
From the [PHP manual](http://www.php.net/manual/en/wrappers.http.php): "Note: HTTPS is supported starting from PHP 4.3.0, if you have compiled in support for OpenSSL"
nikc
@nikc: yup, that is the case and useful info added. Thanks
Sarfraz
Thanks, I wish the error message was more informative! I looked at phpinfo() but didn't know where to look for SSL support info. However, given https wasn't listed in "Registered PHP streams" I'm assuming it's not support. I have an email out to the webhoster to see if this can be changed.
TMC
My webhoster is on a windows stack, so running IIS 7. They have no idea how to troubleshooter this SSL support and claim it should work contrary to it failing. Anyone have specific directions I can give them?
TMC
I think they should turn on the openssl extensin in php ini.
Sarfraz