php - ios push notification performance -
this php push notification code ios below:
<?php // put device token here (without spaces): $devicetoken = "********************************************"; // put private key's passphrase here: $passphrase = "********"; function pushiosnotification($message) { global $devicetoken; global $passphrase; $ctx = stream_context_create(); $path = dirname(__file__).'/ck.pem'; //echo $path; stream_context_set_option($ctx, 'ssl', 'local_cert', $path); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); // open connection 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 connect: $err $errstr" . php_eol); //echo 'connected apns' . php_eol; // create payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default' ); // encode payload json $payload = json_encode($body); // build binary notification $msg = chr(0) . pack('n', 32) . pack('h*', $devicetoken) . pack('n', strlen($payload)) . $payload; // send server $result = fwrite($fp, $msg, strlen($msg)); if (!$result) echo 'message not delivered' . php_eol; else echo 'message delivered' . php_eol; // close connection server fclose($fp); }
this code 1 device,
if need send , support localization,
this code these below.
foreach($devicetokens $devicetoken){ $deviceos = "query device os memcache"; if($deviceos == "ios") { $lang = "query device langauge memcache"; $message = $messagedata[$lang]; pushiosnotification($devicetoken,$message); } }
but doubt performance of code, because devicetokens length number of members.
Comments
Post a Comment