【问题标题】:PHP GAE 1.9.18 - [Errno 8] _ssl.c:507: EOF occurred in violation of protocolPHP GAE 1.9.18 - [Errno 8] _ssl.c:507:EOF 发生违反协议
【发布时间】:2015-05-13 19:37:24
【问题描述】:

这适用于我的谷歌应用引擎,但在我的开发服务器上,我收到此错误:

警告:file_get_contents(https://website.com):无法打开流:设置了不支持的 SSL 上下文选项。存在以下选项,但已被忽略:allow_self_signed<br /> SSL 证书错误 - 证书无效或不存在,[Errno 8] _ssl.c:507: EOF 发生违反协议

$context = stream_context_create(
    array(
        'ssl' => array('verify_peer' => false, 'allow_self_signed' => true),
        'http' => array( 'method' => 'GET' )
    )
);
$call_url = file_get_contents('https://website.com', false, $context);

我正在使用runtime: php55。有谁知道为什么会发生这种情况,为什么它可以在 App Engine 上运行,以及我可以做些什么来解决这个错误?

错误报告:https://code.google.com/p/googleappengine/issues/detail?id=11772

【问题讨论】:

  • 无法在 Mac 上使用 1.9.18 SDK 重现该问题。无论如何,当 verify_peer 设置为 false 时,设置 allow_self_signed 有什么意义?
  • 刚刚重新格式化了我的 Mac。新安装的 mac,新安装的 1.9.18 我收到此错误。在全新安装之前我没有得到这个。我不知道file_get_contents() 向 https 发送请求而不会出错的任何其他方式。 (任何 ssl 标头设置都会出现此错误)。任何建议表示赞赏。 @火星
  • 我在某处读到可能是“2.7 python 中缺乏 SNI 支持”?这有意义吗?终端说我有 Python 2.7.6 @Mars
  • 在这里也可以看到我的 GAE 票 code.google.com/p/googleappengine/issues/detail?id=11707
  • @Mars 有没有办法回滚到 1.9.17,因为如果我不能调用我的服务器,我真的无法开发任何东西。看起来不推荐使用的版本只能到 1.9.9

标签: php google-app-engine ssl


【解决方案1】:

最简单的解决方案是改用 curl,如下所示:

function file_get_contents_curl( $url ) {

  $ch = curl_init();

  curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
  curl_setopt( $ch, CURLOPT_HEADER, 0 );
  curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
  curl_setopt( $ch, CURLOPT_URL, $url );
  curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );

  $data = curl_exec( $ch );
  curl_close( $ch );

  return $data;

}

(向@lord_viper 和PHP : How to use curl instead file_get_contents? 致敬)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    • 2012-12-15
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多