ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195': Connection refused

25,643 views
Skip to first unread message

Flynn

unread,
Jan 18, 2012, 1:00:00 PM1/18/12
to apns-php
My script create this problem.
ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:
2195': Connection refused

i have uploaded the apns 5 different servers( included godaddy.com)
but every server create this problem.
please help me urgently.

derek martin

unread,
Jan 18, 2012, 3:34:01 PM1/18/12
to apns...@googlegroups.com
are you sure your version of PHP has ssl support compiled in? if not,
it will just keep failing.

and...@propellergroup.com

unread,
Feb 14, 2012, 4:18:19 PM2/14/12
to apns-php
Flynn,

Did you ever resolve this issue? I am also stuck with the same error.
I can telnet to the APNS server on port 2195. Also I can use a .NET
utility from the same server to send PUSH messages. But when I try PHP-
APNS it gives me the error:
ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:
2195'

Any help would be appreciated!

Thanks



On Jan 18, 8:34 pm, derek martin <oran...@gmail.com> wrote:
> are you sure your version of PHP has ssl support compiled in? if not,
> it will just keep failing.
>

Minchev

unread,
Mar 28, 2012, 7:28:01 AM3/28/12
to apns-php
HI there,

I also got the same problem.
I have tested it on 2 different servers with open ports and PHP with
ssl,
but the problem still exists.
Will be grateful if somebody share his experience with dissolving the
problem.

Thanks

Minchev

unread,
Mar 29, 2012, 12:45:10 PM3/29/12
to apns-php

As I understand the possible reasons for the upper problem are two:

1. The server have closed the 2195 i 2196 ports.

2. The .pem certificate is not correct

I have eliminated the first option after i changed 3 different servers
for all of them the ISPs guaranteed the ports are open but the problem
remains. The servers had PHP with open SSL and these modules
installed: PCNTL, System V shared memory, semaphore support

For generating .pem certificate i have used these several tutorials:
http://code.google.com/p/apns-php/wiki/CertificateCreation

http://mobile.tutsplus.com/tutorials/iphone/iphone-sdk_apns/

And few more...

After trying around 20 times to create the pem file for 3 different
apps i still got the same error. here is the look of my last pem file:

Bag Attributes friendlyName: Apple Development IOS Push Services:
xxxxxxxxxxxxxx (mine info) localKeyID : 42 0F 51 6D 38 4B 8F 6F 87 CE
70 EC 98 5D 54 C7 1B FC E9 5C subject=/UID=com.nova.pushTestApp/
CN=Apple Development IOS Push Services: xxxxxxxxxxxxxx (mine info)
issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/
CN=Apple Worldwide Developer Relations Certification Authority -----
BEGIN CERTIFICATE----- MIIFdzCCBF
+gAwIBAgIIegORn4VvbB4wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV
BAYTAlVTMRMwEQYDVQQKDApBcHBsZSBJbmMuMSwwKgYDVQQLDCNBcHBsZSBXb3Js...

...bZkkiml3VqhHHn+ys+vH5jPBAeHb5IcYlJV9+I0zCzDBPWfCVvXpIHW2TVFhnZKS
hIGUm3joF24E//w= -----END CERTIFICATE----- -----BEGIN RSA PRIVATE
KEY----- MIIEowIBAAKCAQEA04isqZjMjTG/uDJLrL5/
jSdXkpOeTbVScHGnlMIjVXRWrqXg...

...YTIlH271ZkpXS5dar+6MnMsw+kgqP3xXGGV6ZyAAjRtuDjxxdAi4 -----END RSA
PRIVATE KEY-----

Is there another possible answer to the problem or there is a trick in
creating the .pem file?
I will be very grateful if somebody, who already have encountered this
problem shared his experience of dissolving it.

Aldo Armiento

unread,
Mar 30, 2012, 4:21:01 AM3/30/12
to apns...@googlegroups.com
Please,

try commenting-out this line:

// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

Aldo

Minchev

unread,
Apr 4, 2012, 5:05:07 PM4/4/12
to apns-php
Thank you Aldo,

but i tried this before 2 weeks and it doesn't help.

I have tried the ,pem file like proposing here:

and i have all requirements for the server covered and the problem
still exists.

Is there any connection between the server adn the .pem file ? Should
the sertificate be created from the server?

thank you again,
Minchev

On 30 Март, 11:21, Aldo Armiento <aldo.armie...@gmail.com> wrote:
> Please,
>
> try commenting-out this line:
>
> // Set the Root Certificate Autority to verify the Apple remote peer
> $push->setRootCertificationAuthority('entrust_root_certification_authority. pem'); help

Minchev

unread,
Apr 4, 2012, 5:11:18 PM4/4/12
to apns-php
Sorry,

I meesed the link for the testing :
http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12

"At this point it’s a good idea to test whether the certificate works.
Execute the following command:
$ telnet gateway.sandbox.push.apple.com 2195
Trying 17.172.232.226...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.
This tries to make a regular, unencrypted, connection to the APNS
server. If you see the above response, then your Mac can reach APNS.
Press Ctrl+C to close the connection. If you get an error message,
then make sure your firewall allows outgoing connections on port
2195."

sriniva...@gmail.com

unread,
Aug 26, 2012, 6:15:53 PM8/26/12
to apns...@googlegroups.com, ora...@gmail.com
my php is compiled with --with-openssl command but still i get this error

ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195': 


'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--with-gd' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--with-curl' '--enable-pic' '--with-zlib' '--enable-inline-optimization' '--with-freetype-dir=/usr' '--with-png-dir=/usr/' '--with-jpeg-dir=/usr/' '--with-openssl' '--enable-mbstring' '--with-mcrypt=/usr/local/lib/libmcrypt' 


phpinfo file has this section added as well...

Registered Stream Socket Transportstcp, udp, unix, ud

gpda...@ajnaware.com

unread,
Sep 23, 2012, 8:00:37 PM9/23/12
to apns...@googlegroups.com, capta...@gmail.com
Do you have a passphrase for your certificate? Abstract.php does not support passphrase, so if you have one then you either need to regenerate your certificate without a passphrase, or modify Abstract.php to allow passphrase to be specified.

I experienced the same problem, but was resolved when I added code to support the passphrase.

DK

unread,
Oct 30, 2012, 6:26:03 AM10/30/12
to apns...@googlegroups.com, capta...@gmail.com
We are having this same issue.
We checked and our php has openssl.
We have also tried commenting out the $push->setRootCertificationAuthority line.

Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.push.apple.com:2195': Connection timed out (110)'

Any ideas what to test exactly?

mario.f...@gmail.com

unread,
Nov 4, 2012, 4:33:17 PM11/4/12
to apns...@googlegroups.com, capta...@gmail.com, gpda...@ajnaware.com
I have the same problem and it seem to me it could hang with the PEM phrase (password which I have to set when generating privat_key.pem from Certificates.p12 file). Unfortunately my mac console does not allow my to do the conversion without setting the password. Could you please specify, how did you create the privatkey without setting a password?or how to moodifie Abstract php? Thank you.

Dňa pondelok, 24. septembra 2012 2:00:37 UTC+2 gpda...@ajnaware.com napísal(-a):

Aldo Armiento

unread,
Nov 4, 2012, 4:42:07 PM11/4/12
to apns...@googlegroups.com
Il giorno 04/nov/2012, alle ore 22:33, mario.f...@gmail.com ha scritto:

> I have the same problem and it seem to me it could hang with the PEM phrase (password which I have to set when generating privat_key.pem from Certificates.p12 file). Unfortunately my mac console does not allow my to do the conversion without setting the password. Could you please specify, how did you create the privatkey without setting a password?or how to moodifie Abstract php? Thank you.
>

Please, download version 1.0 stable (https://github.com/duccio/ApnsPHP/tags), now ApnsPHP supports password protected certificates.

Use:

// Set the Provider Certificate passphrase
$push->setProviderCertificatePassphrase('password');

Aldo

thanh...@gmail.com

unread,
Jan 17, 2014, 5:48:39 AM1/17/14
to apns...@googlegroups.com, capta...@gmail.com

shilpija...@gmail.com

unread,
Jan 20, 2014, 2:24:09 AM1/20/14
to apns...@googlegroups.com, capta...@gmail.com
simplepush.php

jcamp...@gmail.com

unread,
Feb 4, 2014, 2:00:05 PM2/4/14
to apns...@googlegroups.com, capta...@gmail.com
I had this problem, but figured out a solution.

I originally used the Apple instructions to create the pem file:

`openssl pkcs12 -in my_private_key.p12 -out my_private_key.pem -nodes`

"my_private_key.pem" didn't work, alone.  You have to make a combined .pem file so:

`openssl pkcs12 -in my_private_key.p12 -out my_private_key.pem -nodes`
`openssl x509 -in aps_development.cer -inform der -out my_dev_cert.pem`
`cat my_private_key.pem my_dev_cert.pem > working_dev.pem`

Inside the "working_dev.pem" file, you should see:

-----BEGIN CERTIFICATE-----

stuff

-----END CERTIFICATE-----

-----BEGIN RSA PRIVATE KEY-----

stuff

-----END RSA PRIVATE KEY-----

I hope this helps someone else

Regards,

John Campbell

adamov...@gmail.com

unread,
Aug 10, 2015, 11:28:47 AM8/10/15
to apns-php, capta...@gmail.com
Hi all
I want to know whether sending push notification to iPhone using php script installed Godaddy hosting server.
Please help me.
I want quick reply.
Thank you.

al...@net-move.net

unread,
Dec 12, 2015, 12:22:12 PM12/12/15
to apns-php, capta...@gmail.com, jcamp...@gmail.com
That saves may day! Thanks a lot dude

bhavingr...@gmail.com

unread,
Apr 26, 2016, 8:51:52 AM4/26/16
to apns-php, capta...@gmail.com
gree...@greencubes.co.in [~/public_html/Projects/feeltok_app]# telnet gateway.push.apple.com 443
Trying 17.172.233.66...
telnet: connect to address 17.172.233.66: Connection refused
Trying 17.172.234.5...
telnet: connect to address 17.172.234.5: Connection refused
Trying 17.172.234.190...
telnet: connect to address 17.172.234.190: Connection refused
Trying 17.172.232.36...
telnet: connect to address 17.172.232.36: Connection refused
Trying 17.172.234.194...
telnet: connect to address 17.172.234.194: Connection refused
Trying 17.172.232.30...
telnet: connect to address 17.172.232.30: Connection refused
Trying 17.172.233.143...
telnet: connect to address 17.172.233.143: Connection refused
Trying 17.172.234.7...
telnet: connect to address 17.172.234.7: Connection refused[/code

As you can see this is also the case when the telnet check if performed from my local computer which has no firewall rules applied to it:

[code]dimitardimov@Dimitar-Dimov:~$ telnet gateway.push.apple.com 443
Trying 17.172.232.231...
telnet: connect to address 17.172.232.231: Connection refused
Trying 17.172.233.145...
telnet: connect to address 17.172.233.145: Connection refused
Trying 17.172.234.8...
telnet: connect to address 17.172.234.8: Connection refused
Trying 17.172.238.220...
telnet: connect to address 17.172.238.220: Connection refused
Trying 17.172.233.156...
telnet: connect to address 17.172.233.156: Connection refused
Trying 17.172.238.222...
telnet: connect to address 17.172.238.222: Connection refused
Trying 17.172.232.229...
telnet: connect to address 17.172.232.229: Connection refused
Trying 17.172.233.152...
telnet: connect to address 17.172.233.152: Connection refused
telnet: Unable to connect to remote host

aszede...@gmail.com

unread,
Aug 9, 2016, 1:25:22 PM8/9/16
to apns-php, capta...@gmail.com
I have the similar problem. 

In localhost, using Wamp, i dont have problem but in the PHP server the problem was generated.  

my code is:



$tToken = '3066d2845a02257e6eXXXXXXXXXXXXX';
//$tToken =$us["devToken"];
$tBody['aps'] = array (
'alert' => 'Mensaje',
'badge' => 1,
'sound' => 'default',
);
$tBody ['payload'] = '{"endereco":"lauro oscar diefenthaeler","tel":"51 3561-8797","numero":"243","complemento":"0","id":"9","nome":"Pia Master","msg":"Pia Master."}';
$tBody = json_encode ($tBody);
$tContext = stream_context_create ();
stream_context_set_option ($tContext, 'ssl', 'local_cert','lla.pem');// lla.pem es el archivo certificado
$tSocket = stream_socket_client ('ssl://gateway.sandbox.push.apple.com:2195', $error, $errstr, 30, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $tContext);
if (!$tSocket){ exit ("APNS Falló la conección: $error $errstr" . PHP_EOL); }
$tMsg = chr (0) . chr (0) . chr (32) . pack ('H*', $tToken) . pack ('n', strlen ($tBody)) . $tBody;
$tResult = fwrite ($tSocket, $tMsg, strlen ($tMsg));
if ($tResult){
//return 1;
echo 1;
}else{
//return 0;
echo 0;
}
fclose ($tSocket);
Reply all
Reply to author
Forward
0 new messages