I am using below php code in Amazon ec2, php 7
<?php
function sendApplePushNotificationMessage( $data, $message )
{
global $notification;
$apns_settings = $notification['apns_user'];
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apns_settings['pemFile']);
$fp = stream_socket_client('ssl://gateway.'.(($apns_settings['environment'] == $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect amarnew: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body+$extra_values);
$msg = chr(0) . pack('n', 32) . pack('H*', $data['token']) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered '.$message. PHP_EOL;
// Close the connection to the server
fclose($fp);
}
when i call this function i got below success message.
Connected to APNS
Message successfully delivered
When i try same pem file and device token to test online then it works properly but not work on Amazon ec2.