Apple Push with proxy and stream_context

I need to send a push notification to iOS devices. My connection must be enabled through a proxy. I tried everything, but to no avail. I have a 110 Connection Timed Out error. It works with cURL if I just try to connect to the Apple push address. I do not know where the problem is. Proxy configuration? PHP stream_context error?

Here is 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 I link directly to Squid? I just realized that the proxy works with Squid. I am also trying to use fopen() instead of stream_socket_client() , but it does not seem to allow the ssl protocol.

Here my var_dump outputs: bool (false) int (110) string (20) "Connection timeout"

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

+6
source share
2 answers

It may just be your proxy server, which does not allow you to open port 2195.

IPhone Removal Notification Unable to connect to SSL server

I think you too:

  • You need to talk to people who run the proxy server to find out if port 2195 is open or not.

or

  • Install a test server listening on port 2195, and then try a test connection to it through a proxy. This should allow you to check if it is a proxy server that blocks connection requests.

or

  • Check if Curl can open the connection using a proxy.

This is done by setting the parameters:

 // 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 test code here .

+1
source
  • create SSL context
  • open tcp socket for proxy server
  • send proxy request to connect to APN
  • Once connected, the connection allows SSL

Take a look at my answer in this post: Send a push notification to APNS through a proxy server

0
source

All Articles