5

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)
TheSabby
  • 267
  • 1
  • 3
  • 12
  • can you post screenshot of your phpinfo() output for these: http://prntscr.com/98p48e and http://prntscr.com/98p4dj sections? If there are any at all. If not (which is likely judging on the symptoms), can you install php openssl extension and retry? – Alexey Nov 30 '15 at 14:53

1 Answers1

2

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

thijsai
  • 1,795
  • 1
  • 18
  • 26
  • An alternative to using iOS push notifications directly is to use Google Cloud Messaging. This answer gives a good example of a GCM backend using PHP: http://stackoverflow.com/a/11253231/3953357 – Adam Mar 22 '16 at 20:56