title: PHP - Google Recaptcha - file_get_contents(): SSL operation failed with code 1
body: <p>I am using the Google ReCaptcha library in my PHP application. It has been working reliably for quite a while now. However, today, I started receiving errors related to the library. </p>
  
  <pre><code>    *[05-Apr-2018 09:19:03 America/Chicago] Severity: 2,Message: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
  error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed,File: E:\inetpub\wwwroot\vendor\google\recaptcha\src\ReCaptcha\RequestMethod\Post.php,Line: 68
  [05-Apr-2018 09:19:04 America/Chicago] Severity: 2,Message: file_get_contents(): Failed to enable crypto,File: E:\inetpub\wwwroot\vendor\google\recaptcha\src\ReCaptcha\RequestMethod\Post.php,Line: 68
  [05-Apr-2018 09:19:04 America/Chicago] Severity: 2,Message: file_get_contents(https://www.google.com/recaptcha/api/siteverify): failed to open stream: operation failed,File: E:\inetpub\wwwroot\vendor\google\recaptcha\src\ReCaptcha\RequestMethod\Post.php,Line: 68*
  </code></pre>
  
  <p>I did not make any changes to my application. The issue just started suddenly and (from my perspective) without logical explanation. </p>
  
  <p>For reference, here is the Post.php from Google's library (not authored by me). </p>
  
  <pre><code>public function submit(RequestParameters $params)
  {
      /**
       * PHP 5.6.0 changed the way you specify the peer name for SSL context options.
       * Using "CN_name" will still work, but it will raise deprecated errors.
       */
      $peer_key = version_compare(PHP_VERSION, '5.6.0', '&lt;') ? 'CN_name' : 'peer_name';
      $options = array(
          'http' =&gt; array(
              'header' =&gt; "Content-type: application/x-www-form-urlencoded\r\n",
              'method' =&gt; 'POST',
              'content' =&gt; $params-&gt;toQueryString(),
              // Force the peer to validate (not needed in 5.6.0+, but still works)
              'verify_peer' =&gt; true,
              // Force the peer validation to use www.google.com
              $peer_key =&gt; 'www.google.com',
          ),
      );
      $context = stream_context_create($options);
      return file_get_contents(self::SITE_VERIFY_URL, false, $context);
  }
  </code></pre>
  
  <p>The last line is "68". I am using PHP 7.1. with <code>OpenSSL 1.0.2k 26 Jan 2017</code>. I am calling the library as follows: </p>
  
  <pre><code>    // validate ReCaptcha
  
  $response = null;
  $reCaptcha = new  \ReCaptcha\ReCaptcha(RECAPTCHA_SECRET);
  if ($_POST["g-recaptcha-response"]) {
      $response = $reCaptcha-&gt;verify(
             $_POST["g-recaptcha-response"],  $_SERVER["REMOTE_ADDR"]
      );
  }
  </code></pre>
  
  <p>Any advice would be greatly appreciated. The application is hosted on IIS and Windows Server.</p>