【发布时间】:2011-01-28 13:40:36
【问题描述】:
我有一个包含以下内容的 PHP 文件,它在开发证书上完美运行,但是当我切换到生产证书时,PHP 错误并给出以下消息,但它只有大约 50% 的时间这样做。其余 50% 有效。有人知道为什么会这样吗?
<?php
// masked for security reason
$deviceToken = 'xxxxxx'; // jq
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', dirname(__FILE__)."/prod.pem");
$number = 5;
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstr\n";
}
else {
print "Connection OK\n";
$msg = $_GET['msg'];
$payload['aps'] = array('alert' => $msg, 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
}
?>
PHP 错误:
警告:stream_socket_client() [function.stream-socket-client]:无法设置本地证书链文件`/var/www/vhosts/thissite.com/httpdocs/prod.pem';检查您的 cafile/capath 设置是否在第 19 行的 /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php 中包含您的证书及其颁发者的详细信息
警告:stream_socket_client() [function.stream-socket-client]:未能在第 19 行的 /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php 中创建 SSL 句柄
警告:stream_socket_client() [function.stream-socket-client]:无法在第 19 行的 /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php 中启用加密
警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /var/www/vhosts/thissite 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误) .com/httpdocs/pushMessageLive.php 第 19 行 连接失败0
【问题讨论】:
-
此脚本是否连续快速运行多次?
-
也许 STREAM_CLIENT_PERSISTENT 标志会有所帮助...
标签: php iphone sdk push apple-push-notifications