我正在尝试连接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中的选项。
启用OpenSSL和Socket支持,并且端口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;