Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jeremy1026

macrumors 68020
Original poster
Nov 3, 2007
2,215
1,029
Hey guys. I am working on an app that implements push. It works great in development mode connecting to the sandbox servers, but it just doesn't play nice with the production servers.

I am using the following PHP code to do the actual pushing.


PHP:
function pushiPhoneMessage($token,$message) {

     $ctx = stream_context_create();
     stream_context_set_option($ctx, 'ssl', 'local_cert', './production1.pem');
     stream_context_set_option($ctx, 'ssl', 'passphrase', 'thepass');
     $fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); //gateway.sandbox.push.apple.com, port 2195 for development
     
     if(!$fp) {
          print "Failed to connect $err $errstr\n";
     } else {
          $payload = json_encode($message);
          //echo $token." > ".$payload."<br/>";
          
          $msg = chr(0) . chr(0) . chr(32) . pack('H*',str_replace(' ', '', $token)) . chr(0) . chr(strlen($payload)) . $payload;
          fwrite($fp, $msg);
          
     }
     fclose($fp);
}

I have the correct password for the certificate in the PHP, I have the certificate on my server, I can push fine using the same script but using sandbox. Can anyone provide any insight to make this work. It's the last step to a giant puzzle.
 
It was a problem with my build, it wasn't connecting to the push server.
 
Hi Jeremy,
I met the same problem, could you help on this, sandbox is ok but production push doesn't accept my certificate
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.