20
votes

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?

2

2 Answers

51
votes

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

1
votes

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);