title: Push Notification in PHP using PEM file
body: <p>I've been working through Ray Wenderlich's tutorials on push notifications using a PHP Script.</p>
  
  <p>Reference: <a href="http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1" rel="nofollow noreferrer">http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1</a></p>
  
  <p><a href="http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2" rel="nofollow noreferrer">http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2</a></p>
  
  <p>I have done a ton of research but I have ran into an issue on part 2 where you run the push.php file using the ck.pem file. </p>
  
  <p><code>/Applications/XAMPP/bin/php push.php development</code> </p>
  
  <p>My only difference is that I'm using XAMPP and not MAMP.</p>
  
  <p>I have confirmed that all the extensions are installed. </p>
  
  <p>I am able to test out my certificate in the terminal by doing this:</p>
  
  <p><code>openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem</code> </p>
  
  <p>It asks me to enter my passphrase and I do. Everything works successfully in the terminal. </p>
  
  <p>However, when I run the push.php file, I get these errors:</p>
  
  <p>PHP Warning:  stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
  error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 
  PHP Warning:  stream_socket_client(): Failed to enable crypto in</p>
  
  <p>PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in on line 140</p>
  
  <p>Line 140 in the php file is:</p>
  
  <p><code>$this-&gt;fp = stream_socket_client('ssl://' . $this-&gt;server, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);</code></p>
  
  <p>I found these:</p>
  
  <p><a href="https://stackoverflow.com/questions/7453015/ios-push-notification-problem-when-using-crontab-scheduler">iOS push notification does not work when using crontab scheduler</a></p>
  
  <p><a href="https://devforums.apple.com/message/1054840#1054840" rel="nofollow noreferrer">https://devforums.apple.com/message/1054840#1054840</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11400556/push-notification-in-php">Push notification in PHP</a></p>
  
  <p>I have literally retried everything. I know my passphrase is correct. I've re-created my certificates, pem files, and keys. Nothing works. Same error every time I do this.</p>
  
  <p>I'm beyond confused. </p>
  
  <p>Does anyone have any suggestions or know what's going on?</p>
  
  <p>Thank you!</p>
  
  <p>UPDATE 1:</p>
  
  <p>I have also tried setting the full path to the ck.pem file that does not fix the error either. </p>