I've implemented Push-Notifications into my Project in Codeigniter(php) years ago and everything was working fine until 10 days ago. My .pem
file is working fine on my local server as well as online notification tools.
Error : "stream_socket_client(): unable to connect to ssl://gateway.push.apple.com:2195 (Connection refused)".
I'm using the following function:
public function applePushSend($deviceToken, $msg){
$mode ='prod';
$ctx = stream_context_create();
if($mode=='dev'){
$gateway = 'ssl://gateway.sandbox.push.apple.com:2195';
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_dev.pem');
}else{
$gateway = 'ssl://gateway.push.apple.com:2195';
stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_prod.pem');
}
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp){
}else{
$alert = array();
$alert['title'] = "My Message";
$alert['body'] = $msg;
$body['aps']['alert'] = $alert;
$body['aps']['badge'] = 1;
$body['aps']['sound'] = 'default';
$body['notificationtypeid'] = 4;
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$pushresult = fwrite($fp, $msg, strlen($msg));
}
fclose($fp);
return($pushresult);
}