2

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
TMC
  • 8,088
  • 12
  • 53
  • 72

1 Answers1

3

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
  • 377,238
  • 77
  • 533
  • 578
  • +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.org May 11 '10 at 08:35
  • 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.org May 11 '10 at 08:39
  • @nikc: yup, that is the case and useful info added. Thanks – Sarfraz May 11 '10 at 08:39
  • 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 May 11 '10 at 08:45
  • 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 May 12 '10 at 03:29
  • I think they should turn on the openssl extensin in php ini. – Sarfraz May 12 '10 at 06:43