title: Time out when sending iOS push Notifications
body: <p>I've been searching for weeks about my problem, but I can't find a solution. I've tried everything related to iOS push notifications service, but nothing works. Here's my problem:</p>
  
  <p>When uploading my <code>php</code> file and <code>.pem</code> file to my server, I get a <code>timed out error</code> when sending the notification.</p>
  
  <ol>
  <li><p>My production certificate is 100% working, because I test the script on my local machine and it sends the notification.</p></li>
  <li><p>I'm using the right URL: <code>gateway.push.apple.com</code> and the right port <code>2195</code></p></li>
  <li><p>I know the device token changes when I'm on production.</p></li>
  <li><p>My server doesn't have Firewall and it has <code>17.xxxx</code> ports opened.</p></li>
  <li><p>I tested notifications in development and it worked on the server.</p></li>
  <li><p>I'm using an absolute path to my certificate <code>/home/project/public_html/ck.pem</code></p></li>
  </ol>
  
  <p>So I just want to know if there's any new configuration that I have to do on my server when changing from development to production, because it worked some time ago with dev certs.</p>
  
  <p>Note that notifications work on my local machine with <code>MAMP</code> and with production cert.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This is the code I use to send a simple notification:</p>
  
  <pre><code>    &lt;?php
  
  
      $deviceToken = 'DISTRIBUTION TOKEN';
  
  
      $passphrase = '*******';
  
  
      $message = 'Hey! It's working';
  
  
  
      $ctx = stream_context_create();
      stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/project/public_html/ck.pem');
      stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
  
      // Open a connection to the APNS server
  $fp = stream_socket_client(
      'ssl://gateway.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,
      'sound' =&gt; 'default'
      );
  
  // 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 'Message not delivered' . PHP_EOL;
  else
      echo 'Message successfully delivered' . PHP_EOL;
  
  // Close the connection to the server
  fclose($fp);
  
  ?&gt;
  </code></pre>