I have implemented Push notification feature in my iOS Application. Push notification message will be pushed from the backend side.

I am using Zend framework on backend side.

Now If I do online tests with push notification it works. So its sure that .pem file created correctly & on iOS side it received push messages correctly.

But while sending push message from backend from zend framework its not working. Its showing the error message like this :

Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Warning: stream_socket_client(): Failed to enable crypto in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/virtual/site71/fst/var/www/html/application/configs/functions.php on line 316

Here is implementation :

function sendIOS($deviceToken){
    $passphrase = '12345678';
    // Put your alert message here:
    $message = 'New stock has been added by Dividend Stock!';

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'pushcert_new.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    if (!$fp)
      exit("Failed to connect: $err $errstr" . PHP_EOL);
    echo 'Connected to APNS' . PHP_EOL;
    // Create the payload body
    $body['aps'] = array(
      'alert' => array(
            'body' => $message,
        'action-loc-key' => 'dinero App',
        'badge' => 1  
    // Encode the payload as JSON
    $payload = json_encode($body);
    // Build the binary notification
    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
    // Send it to the server
    $result = fwrite($fp, $msg, strlen($msg));

    if (!$result)
      echo 'Message not delivered' . PHP_EOL;
      echo 'Message successfully delivered' . PHP_EOL;


Any guidance or hint will be highly appreciated.

0 Answers