title: APNS Connection Issue
body: <p>OK, I know there has been a lot of discussion regarding APNS connection failures.  Most of the discussion recommends checking the outgoing server port 2195 to be sure it will allow the connection.  This is not my problem, although I am experiencing the 'connection refused' error (111).</p>
  
  <p>I have validated communication between my server and the sandbox server be receiving a 200 response from the Apple Gateway.  I know my certificates are good because I have tested the connection using openssl from a Mac.  I have also been able to connect with the gateway <strong><em>once</em></strong> from my server but cannot get a consistent connection. </p>
  
  <p>The test code I am using is as follows:</p>
  
  <pre><code>$ctx = stream_context_create();
  
  stream_context_set_option($ctx,'ssl', 'local_cert', $pem);
  stream_context_set_option($ctx, 'ssl', 'passphrase', $key);
  $gateway = 'gateway.sandbox.push.apple.com';
  $port = '2195';
  
  $remote_socket = 'ssl://'.$gateway.':'.$port;
  $fp = stream_socket_client($remote_socket, $err, $errstr, 60,STREAM_CLIENT_CONNECT, $ctx);
  
  if (!$fp){
      echo $err.'&lt;br&gt;';
      echo $errstr.'&lt;/br&gt;';
      echo 'error=apple failed to connect';
  } else {
      fclose($fp);
      echo 'success';
  }
  </code></pre>
  
  <p>I have placed the .pem file in the same directory as the script file, removed the use of the passphrase, specified verify_peer, used the STREAM_CLIENT_ASYNC_CONNECT and the STREAM_CLIENT_PERSISTENT flags without success.</p>
  
  <p>Is this an issue with something that I am doing, an issue with the apns sandbox server or is this what I should expect from the apns?  Any insights or help you can provide is greatly appreciated -- my hair is getting pretty thin!</p>
  
  <p>Regards.</p>
  
  <p>PS -- If I remove the passphrase I get a 115 error saying the key cannot be accessed.</p>