title: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195' from server side
body: <p>I'm working on an MAC app that use iOS Push Notifications. I want to send the notification from a php script on my server. The code in my app works really good for registering for remote notification and receive them. I use this php script to send notification and it works well too:</p>
  
  <pre><code> &lt;?php
  
  // My device token here (without spaces):
  $deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  
  // My private key's passphrase here:
  $passphrase = 'myPrivateKeyPassword';
  
  // My alert message here:
  $message = 'New Push Notification!';
  
  //badge
  $badge = 1;
  
  $ctx = stream_context_create();
  stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
  stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  
  // Open a connection to the APNS server
  $fp = stream_socket_client(
  'ssl://gateway.sandbox.push.apple.com:2195', $err,
  $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  
  if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);
  
   echo 'Connected to APNS' . PHP_EOL;
  
   // Create the payload body
  $body['aps'] = array(
      'alert' =&gt; $message,
      'badge' =&gt; $badge,
      'sound' =&gt; 'newMessage.wav'
  );
  
  // Encode the payload as JSON
  $payload = json_encode($body);
  
  // Build the binary notification
  $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload))  . $payload;
  
  // Send it to the server
  $result = fwrite($fp, $msg, strlen($msg));
  
  if (!$result)
      echo 'Error, notification not sent' . PHP_EOL;
  else
      echo 'notification sent!' . PHP_EOL;
  
   // Close the connection to the server
   fclose($fp);
  ?&gt;
  </code></pre>
  
  <p>My problem is that if i run this script by terminal on my iMac as well as from other mac system, all works good and notifications are sent, but if I upload it on my server it doesn't work. My certificate is valid and it's in the same folder of the script. When i try to run the script on the server. Then it gives the following error:</p>
  
  <blockquote>
    <p>Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/iphmuvxr/public_html/Schedueling/push_notification.php on line 25</p>
  </blockquote>