iOS push notification does not work when using crontab scheduler

24,372

Solution 1

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

Solution 2

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);
Share:
24,372
RK-
Author by

RK-

Updated on July 09, 2022

Comments

  • RK-
    RK- almost 2 years

    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?

  • DeZigny
    DeZigny about 10 years
    You saved my day as everybody else was saying its something to do with openssl version, thanks
  • Josh Bernfeld
    Josh Bernfeld over 9 years
    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.