PHP无法与苹果通知网关的套接字连接 [英] PHP fails socket connection with Apple notification gateway
问题描述
声明:,所以我发现了很多类似的问题和一些答案,但没有解决我的问题
我有这个简单的PHP code:
I have this easy PHP code:
<?php
$deviceToken = "myDeviceToken";
$message = "Hello from server";
$badge = 1;
$sound = "default";
// Construct the notification payload
$body['aps'] = array(
'alert' => $message
);
if ($badge) {
$body['aps']['badge'] = $badge;
}
if ($sound) {
$body['aps']['sound'] = $sound;
}
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'my.pem');
$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
} else {
print "Connection OK\n";
}
$payload = json_encode($body);
$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);
?>
当从浏览器调用我收到:
[13 - 12月2011年18点52分52秒] PHP的警告:在stream_socket_client()[function.stream插槽客户端]:SSL操作失败,code 1. OpenSSL的错误消息:
错误:14094410:SSL例程:SSL3_READ_BYTES:在/home/srv/public_html/myTest.php SSLv3的警报握手失败第28行
[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /home/srv/public_html/myTest.php on line 28
[13 - 12月2011年18点52分52秒] PHP的警告:在stream_socket_client()[function.stream插槽客户端]:失败,使加密在/home/srv/public_html/myTest.php第28行
[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/srv/public_html/myTest.php on line 28
[13 - 12月2011年18点52分52秒] PHP的警告:在stream_socket_client()[function.stream插槽客户端]:无法连接到SSL://gateway.sandbox.push.apple.com:2195第28行(未知错误)在/home/srv/public_html/myTest.php
[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/srv/public_html/myTest.php on line 28
任何想法是怎么回事呢?
Any idea of what's going on?
推荐答案
从互联网上,可以帮助一些随机调查结果:
Some random finding from the internet which could help:
-
这可能是一个证书的问题。尝试流选项
allow_self_signed
和verify_peer
检查。
尽量明确地用 SSLV2://
或的SSLv3://
在的/ dev / urandom的权限问题
Permission problem on "/dev/urandom"
这篇关于PHP无法与苹果通知网关的套接字连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!