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
6
  • Please add more info... What is your ApnsPHP configuration? Did you change anything before?
    – J. Costa
    Jun 8, 2011 at 13:50
  • no, there where no changes made
    – Tim Specht
    Jun 8, 2011 at 14:10
  • 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)
    – J. Costa
    Jun 8, 2011 at 14:51
  • 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....
    – Tim Specht
    Jun 8, 2011 at 14:59
  • 1
    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.
    – J. Costa
    Jun 8, 2011 at 15:25

7 Answers 7

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.

4
  • It also works for me....But I didn't get the trick. @saurabh How you get into this??
    – Augustine
    Mar 14, 2013 at 12:35
  • 1
    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/tags
    – saurabh
    Mar 15, 2013 at 5:28
  • 1
    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 CA
    – Nish
    Aug 17, 2014 at 16:39
  • 1
    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') line
    – Kiwizoom
    Apr 29, 2015 at 17:30
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. */

4
  • 1
    This worked for me - guessing it must have been a php 7 thing? Sep 29, 2016 at 1:32
  • 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.6 Oct 3, 2016 at 14:25
  • 1
    rather than removing ssl:// , one should enable ssl in php.ini by removing ; before extension=php_openssl.dll and restarting apache server.
    – Dashrath
    Dec 23, 2016 at 8:17
  • 1
    Mine was prefixed with tls:// removing that also fixed it for me Sep 3, 2019 at 13:17
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.

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.
    – Joel Davis
    Mar 10, 2017 at 19:26
0

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

1
  • running on a dedicated server, everythins open
    – Tim Specht
    Jun 15, 2011 at 13:46
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.

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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