简体   繁体   English

stream_socket_client 无法连接(连接超时)

[英]stream_socket_client unable to connect (connection timed out)

I am using the certificate, and the private key我正在使用证书和私钥

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $certfile);
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.xyz.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

Its running in my local XAMPP Server, but its not working in the external server:它在我的本地 XAMPP 服务器中运行,但在外部服务器中不起作用:

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/biranchi/public_html/push.php on line 42警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /home/biranchi/public_html/push.php 中的 ssl://gateway.sandbox.push.apple.com:2195(连接超时)在第 42 行

Failed to connect 110连接失败 110

What is the error?错误是什么? Do i need to change some setting in the server?我需要更改服务器中的某些设置吗?

I had fixed the issue by opening the port 2195 on the production server.我通过在生产服务器上打开端口 2195 解决了这个问题。 You can verify by following command $ telnet gateway.push.apple.com 2195您可以通过以下命令验证 $ telnet gateway.push.apple.com 2195

-bash-3.2# telnet gateway.push.apple.com 2195

Trying 17.149.38.141...
Connected to gateway.push.apple.com (17.149.38.141).
Escape character is '^]'.
Connection closed by foreign host.

Check your personal firewall settings and make sure you're not blocking this out.检查您的个人防火墙设置并确保您没有阻止它。 Try disabling the firewall.尝试禁用防火墙。

Also, some APIs like requests to come from an actual domain rather than a desktop.此外,一些 API 喜欢来自实际域而不是桌面的请求。 I don't have reason to believe Apple works this way, but that's something to check also.我没有理由相信 Apple 是这样工作的,但这也是需要检查的。

Also make sure and ping gateway.sandbox.push.apple.com and make sure you have a good connection.还要确保 ping gateway.sandbox.push.apple.com 并确保您有良好的连接。

You have to set your firewall to allow all the 17.0.0.0/8 block (it all belongs to Apple!).您必须将防火墙设置为允许所有 17.0.0.0/8 块(它都属于 Apple!)。 Check THIS ANSWER检查这个答案

And according to Apple :根据苹果公司的说法:

The APNs servers use load balancing, so your devices won't always connect to the same public IP address for notifications. APNs 服务器使用负载平衡,因此您的设备不会总是连接到相同的公共 IP 地址以获取通知。 It's best to allow access to these ports on the entire 17.0.0.0/8 address block, which is assigned to Apple.最好在分配给 Apple 的整个 17.0.0.0/8 地址块上允许访问这些端口。

If you are using CSF firewall (like me), I'd recommend to add this line to csf.allow file:如果您使用 CSF 防火墙(像我一样),我建议将此行添加到 csf.allow 文件中:

tcp|out|d=2195|d=17.0.0.0/8

Then restart CSF.然后重新启动CSF。 Using the above instead of just "17.0.0.0/8" will allow only outbond connections to Apple and specifically to port 2195. NSA won't like it but this is much more precise and safe!使用上面的而不是“17.0.0.0/8”将只允许外连连接到 Apple,特别是端口 2195。NSA 不会喜欢它,但它更精确和安全! ;) ;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PEAR2 \\ Net \\ Transmitter \\ SocketException:stream_socket_client():无法通过mikrotik连接(拒绝连接) - PEAR2\Net\Transmitter\SocketException: stream_socket_client(): unable to connect (Connection refused) by mikrotik stream_socket_client():无法连接到ssl://gateway.sandbox.push.apple.com:2195(连接被拒绝) - stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) 无法与主机 mailhog 建立连接:stream_socket_client():无法连接到 null://mailhog:1025 - Connection could not be established with host mailhog :stream_socket_client(): unable to connect to null://mailhog:1025 stream_socket_client无法连接到Apple APNS(权限被拒绝) - stream_socket_client unable to connect to Apple APNS (Permission Denied) php,mqtt:stream_socket_client():无法连接到<server><port> - php,mqtt: stream_socket_client(): unable to connect to <server><port> PHP stream_socket_client():无法连接到https - PHP stream_socket_client(): unable to connect to https 连接失败。 错误 #2:stream_socket_client():无法连接到 ssl://smtp.gmail.com:465(连接被拒绝) - Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused) PHP stream_socket_client无法连接 - PHP stream_socket_client fails to connect 连接主服务器stream_socket_client - connect master server stream_socket_client HTTP CONNECT和stream_socket_client - HTTP CONNECT & stream_socket_client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM