7

I have developed a script using stream_socket_client() and it works on my localhost but when I try to use it online (with Fatcow.com web hosting) it won't work. I receive the following error:

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in .../send-notification.php on line 18 Failed to connect 111 Connection refused

This is line 18:

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

I know that the password for the .pem file is correct. The question becomes if I can't use this port what do I do? Is there any free service that I can use? I know that port 80 is open.

I've heard that using the curl() function will work but have been unsuccessful so far.

I would really appreciate getting pointed in the right direction.

1
  • I suppose it is provider blocks outgoing connections, or even apple's server Oct 16, 2013 at 2:23

5 Answers 5

8
+50

In order to send the notifications to the device need to enable 2195 port in the firewall. For security reasons some organizations disabling these ports in the firewall. 2196 port is used for feedback services and this port also should open in the firewall. Without opening these ports messages cannot deliver to APNS.

1
  • How to open these ports on Amazon EC2 server? Feb 24, 2017 at 16:19
3

I believe the following is what you are looking for

$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = 'AppCert.pem';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["458e5939b2xxxxxxxxxxx3"], "aps": {"alert": "test message one!"}}');

$curl_scraped_page = curl_exec($ch);

more information can be found here: Apple push notification with cURL

2
  • are you $url = 'https://gateway.sandbox.push.apple.com:2195'; will work when 2195 is blocked? This is what we are discussing here.
    – Ans
    Dec 9, 2015 at 7:12
  • @Ans The OP never mentions that the port is blocked. This is just an asumption. The OP just says that it is refused. Dec 9, 2015 at 8:48
0

try using port 2196.

I have also faced similar issue, even with cURL you will face this issue. Double check with your hosting provider whether outgoing port (2195,2196) are opened or blocked. Or try to telnet ssl://gateway.sandbox.push.apple.com:2195
and check what response you get. If the ports are opened you will be connected.

0

I had the same problem with my current hosting provider. You could switch to another provider - or - Simply 'buy' a budget LAMP VPS (3 euro/month). And you're good to go

0

in every shared hosting they disable 2195 port for that you can request to enable this port but in most of the shared hosting company dont enable this port so if you want to do ios push notification i recommended you to use Virtual Private Server(VPS) and you can easly configure ios push notification.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.