PHP GAE 1.9.18 - [Errno 8] _ssl.c:507:EOF违反协议发生

时间:2015-03-11 20:09:51

标签: php google-app-engine ssl

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

  

警告: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

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是使用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?

相关问题