title: How to send iOS Push Notifications using TLS and PHP?
body: <p>My app is still in development and I used this tutorial to send iOS Push Notifications using PHP and SSL.</p>
  
  <p><a href="http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1">http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1</a></p>
  
  <p>It was working but it was recently depreciated because Apple recently decided to drop SSL immediately affecting all apps in development and apps in production have until October 29th to change their code.</p>
  
  <p>I would like to know how to do the same thing using TLS instead of SSL.</p>
  
  <p>Here is what my php that used to work looks like:</p>
  
  <pre><code>$ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
  stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  </code></pre>
  
  <p>I tried adding an Entrust certificate as Apple suggests:</p>
  
  <pre><code>$ctx = stream_context_create();
  stream_context_set_option($ctx, 'tls', 'local_cert', 'ck.pem');
  stream_context_set_option($ctx, 'tls', 'passphrase', $passphrase);
  stream_context_set_option($ctx, 'tls', 'cafile', 'entrust_2048_ca.cer');
  $fp = stream_socket_client('tls://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  </code></pre>
  
  <p>But it still doesn't work. Do you have any suggestion to fix it?</p>