title: How can I do an SSL connection with PHP
body: <p>I need to develop a PHP class to communicate with Apple servers in order to do Push notification (APNS). I have the certificate (.pem) and I tried to follow various tutorials found on Internet but I'm still getting error trying to connect to ssl://gateway.sandbox.push.apple.com:2195 with stream socket :</p>
  
  <pre><code>$apnsHost = 'gateway.sandbox.push.apple.com';
  $apnsPort = 2195;
  $apnsCert = 'apns-dev.pem';
  $streamContext = stream_context_create();
  stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
  $apns = stream_socket_client('ssl://'.$apnsHost.':'.$apnsPort, $error, $errorString, 2,
  STREAM_CLIENT_CONNECT, $streamContext);
  </code></pre>
  
  <p>A telnet on this URL works so port 2195 is opened.
  Openssl is activated on PHP since I get "Registered Stream Socket Transports : tcp, udp, ssl, sslv3, sslv2, tls" with a phpinfo().
  My certificate is well read (PHP is_readable(certif.pem) returns true on the file)</p>
  
  <p>Is there anything else to activate in Apache or PHP to get it work ?</p>