$passphrase = "Your_PEM_File_Password_Here";
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_PEM_FILE_PATH_HERE);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// use this when you in sandbox mode..
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
// use this when you in development mode..
// $fp = stream_socket_client(
// 'ssl://gateway.push.apple.com:2195', $err,
//$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
$body['aps'] = array(
'badge' => $badge,
'alert' => "Your Message Here.",
'sound' => 'default',
'content-available' => '1'
);
//echo "<pre>"; print_r($body);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg)); //echo "<pre>"; print_R($result);
if (!$result){
$data = array(
'Message' => 'Message not delivered' . PHP_EOL
);
} else {
$data = array(
'Message' => 'Message successfully delivered' . PHP_EOL
);
} //echo "<pre>"; print_R($result);
fclose($fp);