php 使用 crontab 调度程序时 iOS 推送通知不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7453015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:42:08  来源:igfitidea点击:

iOS push notification does not work when using crontab scheduler

phppush-notificationcrontab

提问by Krishnan

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.

当我手动调用 PHP 脚本通过 APN 推送通知时,我会收到通知。

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

当我使用crontab编写调度程序来自动发送通知时,我没有收到通知。我收到的邮件错误是:

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?

有人可以解释可能是什么问题吗?

回答by Krishnan

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

此问题已修复。真正的问题出在我使用的 PHP 脚本中。

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.

之前在 stream_context_set_option II 中没有包含 ck.pem 文件的完整路径。给出完整路径后没有错误。下面是我现在使用的代码。

$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

苹果论坛问题1

Apple Forum Question 2

苹果论坛问题2

回答by AnilPatel

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