Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

APNS with PHP giving failed to enable crypto error

I am trying to send iOS push notifications using the following PHP code.

I'm not sure if its a syntax or logical error. I have tried regenerating the .pem, checking ports, and checking file permissions. It's all fine. I'm not quite sure what is causing this. I am running this on App Engine. That might be why but I'm not sure. I know that others have successfully done this on Any help would be appreciated.

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'dev.pem');

$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
{
  //Handle Error
}

$body['aps'] = array(
  'alert' => $data["message"],
  'sound' => 'default'
);
$body["postID"] = $data["postID"];
$body["groupID"] = $data["groupID"];
$body["type"] = $data["type"];

$payload = json_encode($body);

foreach ($registrationIds as $registrationID)
{
  $msg = chr(0) . pack('n', 32) . pack('H*', $registrationID) . pack('n', strlen($payload)) . $payload;
  $result = fwrite($fp, $msg, strlen($msg));
}

fclose($fp);

I keep getting the errors :

PHP Warning:  stream_socket_client(): Failed to enable crypto
PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error)
like image 245
TheSabby Avatar asked Nov 01 '22 03:11

TheSabby


1 Answers

I have the same problem and I am sad to say that I just found out that Google App Engine does not support the ssl:// or tls:// stream transporters.

You can find it on this page: https://cloud.google.com/appengine/docs/php/runtime

like image 116
thijsai Avatar answered Nov 11 '22 15:11

thijsai