2

This works on my google app engine, but on my development server, I get this error:

Warning: file_get_contents(https://website.com): failed to open stream: Unsupported SSL context options are set. The following options are present, but have been ignored: allow_self_signed<br /> SSL certificate error - certificate invalid or non-existent, [Errno 8] _ssl.c:507: EOF occurred in violation of protocol in

$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);

I am using runtime: php55. Does anyone know why this is occurring, why it works on App Engine, and what I can do to fix this error?

bug report: https://code.google.com/p/googleappengine/issues/detail?id=11772

bryan
  • 8,879
  • 18
  • 83
  • 166
  • Unable to repro the issue using 1.9.18 SDK on Mac. In any case, what's the point of setting allow_self_signed when verify_peer is set to false? – Mars Mar 12 '15 at 18:39
  • Just reformatted my Mac. Freshly installed mac, freshly installed 1.9.18 I get this error. I didn't get this before a fresh install. I don't know any other way for `file_get_contents()` to send a request to https without getting an error. (I get this error with any ssl header settings). Any suggestions are appreciated. @Mars – bryan Mar 12 '15 at 19:01
  • I read somewhere that it may be "a lack of SNI support in the 2.7 python"? Does that make any sense?Terminal says I have Python 2.7.6 @Mars – bryan Mar 12 '15 at 20:28
  • See my GAE ticket here too https://code.google.com/p/googleappengine/issues/detail?id=11707 – Tom Mar 12 '15 at 22:12
  • @Mars is there a way to roll back to 1.9.17 because I literally can't develop anything if I can't call my server. Looks like deprecated versions only go up to 1.9.9 – bryan Mar 19 '15 at 20:09
  • @Mars It won't let me get here unless I can sign on with a google.com credentials. I'd also like to solve this. I'm willing to help anyway I can. What I did was, reformat my mac os x yosemite with a fresh installation. And immediately went and downloaded 1.9.18 and started working on my app engine locally. I installed nothing else. – bryan Mar 20 '15 at 03:12
  • My bad. Posted the correct URL: https://console.developers.google.com/storage/browser/appengine-sdks/deprecated/1917/ Please test 1.9.17 in your fresh environment and see if the issue still persists. – Mars Mar 30 '15 at 16:28
  • @Mars i'm still getting this error (1.9.23) – bryan Aug 24 '15 at 20:36

1 Answers1

0

The easiest solution is to use curl instead, as such:

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;

}

(hat tip to @lord_viper and PHP : How to use curl instead file_get_contents?)

Community
  • 1
  • 1
Ben Shoval
  • 1,732
  • 1
  • 15
  • 20