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

  • Home
  • SEARCH
  • 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 6345173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:46:15+00:00 2026-05-24T20:46:15+00:00

My task is sending push notification to multiple users which is working fine with

  • 0

My task is sending push notification to multiple users which is working fine with following function

function push_to_apns_badge($token_array)
{
    $apnsHost = 'gateway.sandbox.push.apple.com';
    $apnsPort = 2195;
    $pem_path  = MODULE_DIR.'push_notification'.DIRECTORY_SEPARATOR;
    $apnsCert = $pem_path.'apns-dev.pem';

    if(is_array($token_array) && count($token_array))
    {       
        foreach ($token_array as $token)
        {
            $streamContext = stream_context_create();
            stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

            $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
            $badge_count = (int)$token['badge'];
            $payload = get_payload_badge($badge_count);

            $apnsMessage = get_one_message_to_write_badge($token['token'],$payload);
            $wrt = fwrite($apns, $apnsMessage); 

            $_error_str .= " $error $errorString ";
            socket_close($apns);
            fclose($apns);
        }
    }   
    return array(true,$_error_str); 
}

But it will take too much cpu usage.

Can I improve Performance somehow? or something missing there?

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-24T20:46:16+00:00Added an answer on May 24, 2026 at 8:46 pm

    You are making too many connections to Apple and they could block you if you do it this way.

    I suspect the creating and tearing down of the connection with each message is also your slow point there!

    Apple recommend opening a connection, sending your messages, leaving it open for as long as you can, and to send future messages down that same connection too.

    You may want to look at Urban Airship which will send 1 million messages a month free?

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

Sidebar

Related Questions

TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Task: I have a camera mounted on the end of our assembly line, which
The task is to take a list of tables which is changeable. Write a
I have one task to developer an application in which user can press the
I find the Post notification and delegate function are very useful in iOS. Once
Hai guys, My website has thousands of users... I have implemented a background task
In my application, I am sending periodic cron and background task requests to refresh
I have an interesting task: to write a program which captures input from the
I have a time consuming task (iterating through files and sending it's content to
I built a custom rake task to send emails to my users, but I

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.