【问题标题】:file_get_contents() -> SSL operation failed with code 1file_get_contents() -> SSL 操作失败,代码为 1
【发布时间】:2015-04-27 16:44:45
【问题描述】:

多年来,我拥有这段代码来获取特定 Facebook 页面的赞:

$url = 'https://graph.facebook.com/<facebook site id>';
echo json_decode(file_get_contents($url))->{'likes'};

现在我们升级到 PHP 5.6,它停止工作并出现以下错误消息:

Warning: file_get_contents() [function.file-get-contents.php]: SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in <some page> on line 182

Warning: file_get_contents() [function.file-get-contents.php]: Failed to enable crypto in <some site> on line 182

Warning: file_get_contents(https://graph.facebook.com/<facebook site id>) [function.file-get-contents.php]: failed to open stream: operation failed in <some page> on line 182

有没有简单的方法来解决这个问题?

我知道有一个参考答案,但这个答案会禁用 SSL 验证,我不想实现可能的安全漏洞!

【问题讨论】:

    标签: php json facebook ssl curl


    【解决方案1】:

    从 cURL 7.10 开始,CURLOPT_SSL_VERIFYPEER 默认设置为 TRUE 您可以再次将其设置为 FALSE,但设置 CA 证书会更明智(请参阅http://php.net/manual/en/function.curl-setopt.php 了解更多信息)。

    另外,请记住 file_get_contents 将在超时时返回 FALSE,因此最好执行以下操作: - 设置比默认 php 超时 0 秒更低的超时 - 处理任何 FALSE 的返回

    【讨论】:

      猜你喜欢
      • 2021-05-14
      • 2016-12-19
      • 2014-11-26
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 1970-01-01
      • 2016-09-07
      • 2015-01-21
      相关资源
      最近更新 更多