20

I have implemented a sample push notification service for my App.

Right now I test in a sandbox environment.

I get notifications when I manually call the PHP script to push notifications through APN.

When I write a scheduler using crontab to automate the delivery of notifications I dont get the notifications. The error I get as a mail is:

PHP 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 /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning:  stream_socket_client(): Failed to enable crypto in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
PHP Warning:  stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Users/aspire/Desktop/SimplePush/simplepush.php on line 21
Failed to connect: 0 

Can someone explain what the problem could be?

RK-
  • 12,099
  • 23
  • 89
  • 155

2 Answers2

51

This problem was fixed. The real issue was in the PHP script I used.

Earlier in the stream_context_set_option I I did not include the full path to the ck.pem file . After giving the full path there was no error. Below is the code I am using right now.

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/Users/Development/Dev/ck.pem');

Some others who have had this problem and their discussions are

Apple Forum Question 1

Apple Forum Question 2

RK-
  • 12,099
  • 23
  • 89
  • 155
  • 2
    You saved my day as everybody else was saying its something to do with openssl version, thanks – DeZigny May 12 '14 at 07:34
  • 1
    This question has only become more relevant after apple switched to tls1.0. I am making a comment so others who google search tls1.0 can find this solution. – Josh Bernfeld Feb 05 '15 at 01:56
1

try this code

    $apnsCert = $_SERVER['DOCUMENT_ROOT'].'/..../..../ck.pem';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert',$apnsCert);
    stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);
AnilPatel
  • 2,356
  • 1
  • 24
  • 40