title: unable to connect to APNS (connection time out)
body: <p>I had succeeded earlier on sending a push notification to my iPhone using raywenderlich's excellent tutorial here <a href="http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1" rel="nofollow">http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1</a> and running the php script using the mac terminal, however, now I am trying to achieve the same thing only now I have the push.php script uploaded to my server and run the script every 5 min via Cron Job but i get this error now:</p>
  
  <p><strong>stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out)</strong></p>
  
  <p>Like I said before it was working fine earlier when I was running the script through the terminal. I think the problem is that the php script from the server cannot access my push certificates. How do I give the script access to them? Please help!</p>
  
  <p>Heres the php script if it helps:</p>
  
  <pre><code>&lt;?php
  
  
  // Assign data into variables
  $deviceToken = "e39ffc6b98f649f127d07d2d881bc9faa621a3c5d59f9647e64f6452fc37af6c";
  $passphrase = "9q3n6k80";
  $sound = '';
  $blank = "";
  
  $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; "mic check",
      '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 succesfully delivered' . PHP_EOL;
  
  // Close the connection to the server
  fclose($fp); 
  </code></pre>
  
  <p>Thank You!</p>
  
  <blockquote>
    <p>EDIT: Im using the File Manager in Bluehost to upload files</p>
  </blockquote>