Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple Push with proxy and stream_context

I have to send push notification to iOS devices. My connection has to be enabled through a proxy. I tried everything but without success. I have an error 110 Connection Timed Out. It's working with cURL if I just try to connect to Apple push's address. I don't know where the problem is. Proxy config ? PHP stream_context wrong implementation ?

Here's my code :

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'certificate.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'my_passphrase');
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
stream_context_set_option($ctx, 'http', 'proxy', 'tcp://my-proxy.net:8080');
stream_context_set_option($ctx, 'http', 'request_fulluri', true);

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

Do you have an idea ?

EDIT:

Can it be directly linked to Squid ? I just figured out the proxy is running with Squid. I also try with fopen() function instead of stream_socket_client() but it seems it doesn't allow ssl protocol.

Here's my var_dump outputs : bool(false) int(110) string(20) "Connection timed out"

I also have this warning : Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /share/www/website/test.php on line 22

like image 431
Pierre Avatar asked Dec 19 '12 12:12

Pierre


1 Answers

It could simply be your proxy does not allow port 2195 to be opened.

iPhone Push Notification Unable to Connect to the SSL Server

I guess you either:

  • Need to talk to the people who run the proxy to see if port 2195 is open or not.

or

  • Setup a test server listening on port 2195 and then try to do a test connection to it through the proxy. That should allow you to test if it is the proxy that is blocking the connection requests.

or

  • Test whether Curl can open the connection using a proxy.

Which is done by setting the options:

// sets the proxy to go through
curl_setopt($ch, CURLOPT_PROXY, $proxy);
// sets to use a tunnel proxy which most http proxies are
curl_setopt($ch, CURLOPT_HTTPTUNNELPROXY, $proxy);

Full testing code here.

like image 116
Danack Avatar answered Nov 14 '22 13:11

Danack