20% Discount for all products. Limited Availability.
0

iPhone Push Notifications PHP Server

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_.PEM_FILE);
stream_context_set_option($ctx, 'ssl', 'passphrase', YOUR_PASSPHRASE);
 
$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<BR><BR>");
}
 
echo 'Connected to APN<BR>';
 
 
// Create the payload body
$body['aps'] = array(
 'badge' => +1,
 'alert' => 'Testing push notifications',
 'sound' => 'new_wall_paper.wav',
 'action-loc-key' => 'OK'
);
 
$payload = json_encode($body);
 
for ($i = 0; $i < count($tokens); $i++) {
 $msg = chr(0) . pack('n', 32) . pack('H*', $tokens [$i]) . pack('n', strlen($payload)) . $payload;
 fwrite($fp, $msg, strlen($msg));
}
 
echo "Completed sending messages";
fclose($fp);