gpt4 book ai didi

php - 推送通知有时不起作用,有时它起作用。收到警告 SSL3_WRITE_PENDING :bad write retry and SSL: Broken pipe

转载 作者:太空宇宙 更新时间:2023-11-03 14:40:50 25 4
gpt4 key购买 nike

$passphrase = '';
$deviceToken="8ebf42fd63c37071b9309f938a527189525b777f35571fc249ec1ed2581d3441";
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', "pushCert.pem");
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
{
exit("Failed to connect: $err $errstr" . PHP_EOL);
return 0;
}
// Create the payload body
$body['aps'] = array(
'notification_type_id'=>1,
'contest_id'=>1,
'pic_id'=>1,
'rid'=>1,
'alert' => "Hi John test push",
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
{
echo 'Message not delivered' . PHP_EOL;
}else{
echo 'Message successfully delivered' . PHP_EOL;
}

为什么推送通知有时有效有时无效?向 IOS 设备发送推送通知时出现以下警告

Severity: Warning

Message: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry

Filename: models/cron_win_contest_model.php

Line Number: 386

或者

Severity: Warning

Message: fwrite(): SSL: Broken pipe

Filename: models/cron_win_contest_model.php

Line Number: 386

你能帮我解决这个问题吗

最佳答案

当您尝试写入套接字时。如果出现问题,fwrite 将返回 false0(取决于 php 版本)作为返回值。当它发生时,您必须对其进行管理。

换个方式,在fwrite()之前加上sleep(5)

你可以这样做:-

try {                           
$result = fwrite($fp, $msg, strlen($msg));
}
catch (Exception $ex) {
sleep(5); //sleep for 5 seconds
$result = fwrite($fp, $msg, strlen($msg));
if ($result)
{
return true;
}
else {
return false;
}
}

希望对您有所帮助!

关于php - 推送通知有时不起作用,有时它起作用。收到警告 SSL3_WRITE_PENDING :bad write retry and SSL: Broken pipe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43276122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com