无法从 php 连接到 apns
我在从我的生产机器(它是 vps 托管)连接到 Apple apns 时遇到问题。
- 我询问了托管技术援助,他们说他们不会阻止任何端口上的传出连接,并且日志没有显示任何此问题,他们不知道可能导致此问题的原因,因此没有帮助。
- 这适用于我的本地开发机器,iPhone 会收到通知。
extension=php_openssl.dll
已在两台计算机上的php.ini
文件中启用。- 在两台机器上
telnet
都会出现黑屏,并且不会像我在此处的某些线程上看到的那样做出响应。
我使用的代码是:
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
fclose($apns);
我得到的错误是:
Warning: stream_socket_client(): SSL: crypto enabling timeout in test.php on line 116
Warning: stream_socket_client(): Failed to enable crypto in test.php on line 116
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in test.php on line 116
Warning: fwrite() expects parameter 1 to be resource, boolean given in test.php on line 118
Warning: fclose() expects parameter 1 to be resource, boolean given in test.php on line 119
最后两个错误是连接失败时给出的,但前三个错误我无法解决。
任何帮助将不胜感激:)
I am having trouble connecting to the apple apns from my production machine, its a vps hosting.
- I asked the hosting technical assistance and they said that they do not block outgoing connections on any port and that the logs show nothing of this problem and they have no idea what might cause this, so no help there.
- This works on my local dev machine and the iPhone gets the notifications.
extension=php_openssl.dll
is enabled in thephp.ini
file on both machines.- on both machines
telnet
gives a black screen and not a response like i saw on some threads here.
The code im using is:
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
fclose($apns);
And the error I get are:
Warning: stream_socket_client(): SSL: crypto enabling timeout in test.php on line 116
Warning: stream_socket_client(): Failed to enable crypto in test.php on line 116
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in test.php on line 116
Warning: fwrite() expects parameter 1 to be resource, boolean given in test.php on line 118
Warning: fclose() expects parameter 1 to be resource, boolean given in test.php on line 119
The last two errors are a given as the connection fails, but the first three I can't resolve them.
Any help will be appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论