ApnsPHP can't connect to Apple Gateway
Asked Answered
T

7

13

suddenly a really strange error appeared today, saying that it isn't able to connect to the appropriate gateway...any fix suggestions?

Here's the logger output:

Wed, 08 Jun 2011 15:05:44 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: INFO: Retry to connect (1/3)...
Wed, 08 Jun 2011 15:05:46 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: INFO: Retry to connect (2/3)...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Retry to connect (3/3)...
Wed, 08 Jun 2011 15:05:49 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...

Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)' in /home/xxxx/xxxxx/ApnsPHP/Abstract.php:354
Too answered 8/6, 2011 at 13:8 Comment(6)
Please add more info... What is your ApnsPHP configuration? Did you change anything before?Pion
no, there where no changes madeToo
add this to the beginning of your script ini_set("display_errors", 1); and see if you get any php errors (dont forget to remove this line in production)Pion
no, there aren't any php errors...could it be that Apple got problems with their own servers? I tried the "sample_push.php" which was delivered with ApnsPHP initially and it get's the same error....Too
Nop, I have a web page to send push notifications (via sandbox and "live" servers), I tested both about 30 minutes ago and it is working.Pion
so any suggestions what I'm missing? Do I need to renew profiles or anything else?Too
O
18

This solution worked for me. The original answer is on Push notifications server implementation -

I have found a solution, I don't know if it's the best, but it works. On Abstract.php (this file is part of the apns-php source) I have commented the line 343. Now it looks like this:

$streamContext = stream_context_create(array('ssl' => array(
//'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
'cafile' => $this->_sRootCertificationAuthorityFile,
'local_cert' => $this->_sProviderCertificateFile
)));

I really don't know what is the point of this line, but know the push notification is working properly.

Occasion answered 2/8, 2011 at 14:39 Comment(4)
It also works for me....But I didn't get the trick. @Occasion How you get into this??Brothel
No, I am not sure how or why this line causes problem. I am not into PHP much either. But APNSPHP has released a new version after I faced and fixed this problem. Hopefully it works without any problem in new version. github.com/duccio/ApnsPHP/tagsOccasion
This means you are disabling verify peer using Entrust Root Certification Authority, double check your root CA most probably you might be using same file for SSL client authentication and the root CAReverend
If you don't want to disable verify peer, here is ApnsPHP cert guide code.google.com/p/apns-php/wiki/CertificateCreation to get your Root Cert 2048 and use it in the $push->setRootCertificationAuthority('rootcert.pem') lineFascist
M
10

im my case i change line 58 and 59 File ApnsPHP/Push.php This protected $_aServiceURLs = array( 'ssl://gateway.push.apple.com:2195', // Production environment 'ssl://gateway.sandbox.push.apple.com:2195' // Sandbox environment ); /< @type array Service URLs environments. */ With protected $_aServiceURLs = array( 'gateway.push.apple.com:2195', // Production environment 'gateway.sandbox.push.apple.com:2195' // Sandbox environment ); /< @type array Service URLs environments. */

Maomaoism answered 31/8, 2016 at 16:17 Comment(4)
This worked for me - guessing it must have been a php 7 thing?Paleoecology
I'm not sure but i thinks is about the php configuration env. Im not test it on php 7. Was tested with php 5.6Maomaoism
rather than removing ssl:// , one should enable ssl in php.ini by removing ; before extension=php_openssl.dll and restarting apache server.Brisket
Mine was prefixed with tls:// removing that also fixed it for meYancey
B
4

You might check you have the right certificates installed. Look into this URL: https://code.google.com/p/apns-php/wiki/CertificateCreation to generate 'entrust_root_certification_authority.pem' file.

You can skip the certificate validation by commenting the following line on sample_push.php:

    //$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

Hope that it helps. Regards.

Bethelbethena answered 7/5, 2013 at 15:30 Comment(1)
Apples pem files expire every 13 months and need to be replaced. The accepted answer might be the quickest way to fix the issue, but it's bypassing a security check, this should be the accepted answer based on best practice.Cardinal
F
0

Please check with ports specified in apple doc. You have to open the ports on your provider side system.

Fulk answered 15/6, 2011 at 13:24 Comment(1)
running on a dedicated server, everythins openToo
S
0

I got the same error. I google a lot and follow every step of this guide, make sure my pem file is generated rightly: https://code.google.com/p/apns-php/wiki/CertificateCreation

then i run below command to check is the secure link to apns right or not:

 openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem 

Press enter and i got this prompt :

Enter pass phrase for apns-dev-key.pem:

then i realize that i forgot set passphrase for cert(it is dev.pem in my case)

// Instantiate a new ApnsPHP_Push object
$this->push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'dev.pem'
);
// Set the Provider Certificate passphrase
$this->push->setProviderCertificatePassphrase($passphrase);
// Set the Root Certificate Autority to verify the Apple remote peer
$this->push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$this->push->connect();
// Instantiate a new Message with a single recipient
$this->message = new ApnsPHP_Message($deviceToken);

set the right passphrase for the apns pem, problem solved.

Steakhouse answered 7/7, 2014 at 10:39 Comment(0)
R
0

I had same issue and what I did wrong was providing same certificate for SSL client authentication and the root CA, below code worked for me

$push = new ApnsPHP_Push(
        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
        'ck.pem'
    );

$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

https://code.google.com/p/apns-php/wiki/CertificateCreation

Reverend answered 11/8, 2014 at 13:58 Comment(0)
W
0

Developer need to export APNS certificate and its key differently. If both are exported in one go then this error will arise.

Wolves answered 21/7, 2017 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.