【发布时间】:2013-03-27 21:58:17
【问题描述】:
我有一个 iOS 应用程序,当我在我的网站上写新帖子时,我使用苹果推送通知来发送通知,所以有 php 脚本具有 ssl 证书,当我发送推送通知时它通常会发送但出现错误日志我收到此错误:
[27-Mar-2013 15:30:44] PHP 致命错误:最长执行时间为 30 第 56 行 /home3/basiphon/public_html/Push.php 中超过的秒数
推送通知(通常)发送成功,但我在错误日志中收到此错误,有时推送通知未发送,我也收到此错误到另一个类似这样的错误:
[27-Mar-2013 05:45:04] PHP 警告:stream_socket_client() [function.stream-socket-client]: SSL:/home3/basiphon/public_html/Push.php 中的连接超时 第 56 行 [27-Mar-2013 05:45:04] PHP 警告:stream_socket_client() [function.stream-socket-client]: 无法在 /home3/basiphon/public_html/Push.php 中启用加密 第 56 行 [27-Mar-2013 05:45:04] PHP 警告:stream_socket_client() [function.stream-socket-client]: 无法连接到 ssl://gateway.push.apple.com:2195(未知错误) 在 /home3/basiphon/public_html/Push.php 第 56 行
请看我的 push.php 脚本代码:
`// 打开到 APNS 服务器的连接
$fp = stream_socket_client(
$url, $err,
$errstr, 2, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// 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 delivered111' . PHP_EOL;
$query_update="update wp_apns_messages set status='delivered',delivery=NOW() where pid='$pid'";
$res_update=mysql_query($query_update) or die(mysql_error());
}
// Close the connection to the server
fclose($fp);`
【问题讨论】:
-
请在此处以文本形式发布相关的 PHP 代码,有一大堆原因导致屏幕截图不是一个好主意。
-
好的,谢谢汤姆,这里是我的push.php脚本的完整代码,我将编辑帖子并放置脚本代码的文本
-
我应该提到,您需要编辑您的问题,而不是发表评论,使用代码。
-
我编辑了问题,我不能放完整的代码,但我添加了脚本的最后一部分。
标签: php ios push-notification