Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6583555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:25:27+00:00 2026-05-25T16:25:27+00:00

I’m testing an iPhone app with push notifications. In the last 5 days I

  • 0

I’m testing an iPhone app with push notifications.

In the last 5 days I got it working few times (and it usually worked for consecutive notifications in a range of time of few minutes).

Instead I almost always get the error message: “Connection failed”.

Since it worked few times, I assume the code to be correct, and the certificates valid as well. So I have no clue how to solve this.

I’ve also tried to connect multiple times with the following code:

$ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');

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

    for ( $tries = 5, $interval = 10, $fp = false; !$fp && $tries > 0; $tries-- ) {
      if (!($fp)) {
        print "Failed to connect $err $errstrn"; 
        sleep ( $interval );
      }
    }

    if ($fp) {

            ...

Output:unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused)

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:25:28+00:00Added an answer on May 25, 2026 at 4:25 pm

    The code looks mostly correct. I would suggest that you don’t need the loop (I never have); and it might even cause you trouble if you are over-sending the same requests. I’m not sure why you would have some successes and some failures, I have found APN servers to be pretty consistent.

    One detail to check: the PHP code you’re using does not include a password in the ssl options; this is required if the pem file you are using is password-protected. (See code below for example)

    I would recommend re-validating the credentials you authenticate with. The best way to do this is to use openssl (from terminal) as described in Apple’s troubleshooting technote 2265: http://developer.apple.com/library/ios/#technotes/tn2265/_index.html. I’ve written up a good walkthrough on the following SO question: Couldn't able to connect to APNS Sandbox server

    After validating the pem file, you could try using the following PHP code (stolen from my test page):

    // Put your private key's passphrase here:
    $passphrase = 'p-a-s-s-p-h-r-a-s-e';
    
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'CertificateAndPrivateKey.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
    
    // Open a connection to the APNS server
    $fp = stream_socket_client('ssl://gateway.push.apple.com:2195',
        $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
    
    if (!$fp)
        exit("Failed to connect: $err $errstr" . PHP_EOL);
    
    echo 'Connected to APNS' . PHP_EOL;
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i got an object with contents of html markup in it, for example: string
I am writing an app with both english and french support. The app requests
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.