苹果推送通知服务的连接,通过代理,超时在stream_socket_client(Apple Pus

2019-10-18 11:11发布

我试图连接APNS,但我需要通过代理,这里的连接测试的代码:

if (!extension_loaded('openssl')) {
    exit("need openssl");
}

$http = array();
$http['http']['proxy'] = 'tcp://proxy.net:8080';
$http['http']['request_fulluri'] = true;

$ssl = array();
$ssl['ssl']['local_cert'] = 'ck.pem';
$ssl['ssl']['passphrase'] = 'passphrase';

$opts = array_merge($http,$ssl);

$context = stream_context_create($opts);

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $context);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

问题是,我一直超时错误,就像如果我直接连接到苹果网关一样,如果在stream_context_creat选项中ognored。

OpenSSL和插座支持被启用,并且端口2195打开。

有任何想法吗?

编辑1:

试图连接到代理只有它的工作原理

$fp = stream_socket_client('tcp://proxy-dmz.pgol.net:8080', $err, $errstr, 60, STREAM_CLIENT_CONNECT);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected!' . PHP_EOL;

编辑2:

而像这样的脚本(在一些论坛上找到)似乎工作...我卡

$ip = "tcp://proxy.net"; // proxy IP
$port = "8080"; // proxy port

$url = "http://search.yahoo.com/search?p=test";

$request = "GET $url HTTP/1.0\r\nHost:www.yahoo.com:80\r\n\r\n";

$fp = fsockopen($ip,$port); // connect to proxy

fputs($fp, $request);

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);

fclose($fp);

print $data;
文章来源: Apple Push Notification Service connection, through proxy, timed out with stream_socket_client