通知推送ios:对等连接重置 [英] notifications push ios: Connection reset by peer

查看:192
本文介绍了通知推送ios:对等连接重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Apple设备创建一个通知系统,但是当我尝试在服务器上运行它时遇到以下错误:

I’m trying to do a notifications system for apple devices, but I’m getting the following errors when I try to run it on the server:

警告:stream_socket_client():SSL:对等连接重置连接 /home/empresa/public_html/simplepush/push.php,第30行

Warning: stream_socket_client(): SSL: Connection reset by peer in /home/empresa/public_html/simplepush/push.php on line 30

警告:stream_socket_client():无法启用加密 /home/empresa/public_html/push/push.php,第30行

Warning: stream_socket_client(): Failed to enable crypto in /home/empresa /public_html/push/push.php on line 30

警告:stream_socket_client():无法连接到 ssl://gateway.sandbox.push.apple.com:2195(未知错误)在 第30行的/home/empresa/public_html/push/push.php无法连接: 0

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/empresa /public_html/push/push.php on line 30 Failed to connect: 0

我的代码是这样的:

  <?php
ini_set('display_errors','On'); 
error_reporting(E_ALL);
$deviceToken= 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';      
$passphrase = ' ';
$message = 'my first notification';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$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' => $message,
    'sound' => 'default'
    );

// 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;
else
    echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);

可能会发生什么?谢谢.

What could be happening? Thanks.

推荐答案

我不确定具体原因

但是请确保您没有做错以下任何事情:

  • 不要并行建立许多连接.要么重用相同 推送后连接或关闭连接 通知.实际上,服务器有最大数量限制 并行连接,一旦您 达到阈值.此外,苹果公司建议保持连接开放,除非 你知道它会闲置的.

  • Don't make many connections in parallel. Either reuse the same connection or close the connection after delivering Push Notifications. Actually, servers have a limit for maximum number of parallel connections, which might leave you in trouble, once you reach threshold. Also Apple suggests leave a connection open unless you know it will be idle.

使您与APN的连接在多个通知中保持打开状态;不要反复打开和关闭连接. APNs将快速连接和断开视为拒绝服务攻击.除非您知道连接会长时间闲置,否则应该保持连接打开状态.例如,如果您每天仅向用户发送一次通知,则可以每天使用一个新的连接.

Keep your connections with APNs open across multiple notifications; don’t repeatedly open and close connections. APNs treats rapid connection and disconnection as a denial-of-service attack. You should leave a connection open unless you know it will be idle for an extended period of time—for example, if you only send notifications to your users once a day it is ok to use a new connection each day.

请勿将开发者配置文件令牌发送到LIVE APNS.保持 分发和开发应用程序令牌是分开的.可能导致 错误,如果您尝试将沙盒令牌发送到LIVE APNS,反之亦然.

Don't send out developer profile tokens to LIVE APNS. Keep distribution and development app tokens separate. It could result in error, if you try to send sandbox tokens to LIVE APNS or vice versa.

源- APNS-通知推送ios:对等PHP重置连接

这篇关于通知推送ios:对等连接重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆