Apple Push Notification Service connection, through proxy, timed out with stream_socket_client

坚强是说给别人听的谎言 提交于 2019-12-11 09:04:51

问题


I'm trying to connect APNS, but i need to pass through a proxy, here the connection test code:

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;

The problem is that I have always a timeout error, like if i make a direct connection to apple gateway, like if options in stream_context_creat were ognored.

OpenSSL and Socket support are enabled, and port 2195 is open.

Any ideas?

Edit 1:

Trying connect to proxy only it works

$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;

Edit 2:

And a script like this (found in some forum) seems to work... i'm stuck

$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;

来源:https://stackoverflow.com/questions/18085086/apple-push-notification-service-connection-through-proxy-timed-out-with-stream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!