Max number of devices to send to APNS socket sever

家住魔仙堡 提交于 2019-12-21 18:02:28

问题


Our push notification script that has worked for almost a year has suddenly stopped working. The script does the following:

  1. Queries a DB for a list of iPhone device tokens

  2. Opens an SSL socket connection to Apple's live APNS server

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
    stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
    $fp = stream_socket_client($apnsHost, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    
  3. creates a payload with a 255 byte sized message

    $payload = '{
      "aps": {
         "alert": "' . $message . '",
         "badge": 1,
         "sound": "default"
      }
    }';
    
  4. Loops through each device and writes the payload to the open connection.

    $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    fwrite($fp, $msg);
    
  5. The connection is then closed.

    fclose($fp);
    

So my question is this-- nothing in the script has changed, but what HAS changed is the size of the database. I created a web interface that allows a user to send a payload to all iphone devices and when it runs it only takes a few seconds to send/load. Is it possible though that the number of devices in the DB (around 3500) is creating the problem?

What is the maximum number of devices that I can I send a push notification to when I write to the socket? Does a max or limit exist?


回答1:


The problem wasn't the number of devices to sent to APNS. The problem turned out to be that Apple changed their API. You now need to check every single device to see if it's still valid (ie. if they are denying push notificaitons, if the device deleted the app, etc.). If the device no longer accepts push notifications from your app and you send one to it anyways, Apple immediately drops the connection to your APNS socket. I now have a cronjob that runs a program once a day that checks and deletes any devices from my database that no longer accept push notifications (Apple has this list). But be careful -- once you pull the list of disabled device ids from Apple, Apple deletes it from their server and you can never pull it again.

You also need to update your push notification code to check if the connection is ever dropped. When the connection is dropped, the program needs to reestablish the connection and try to push again.




回答2:


Indeed, based on experience, it seems that connections to APNS will fail after some number of notifications have been pushed through it. In our own APNS library (http://code.google.com/p/javapns/), the multithreaded transmission engine included in the library automatically restarts connections after pushing 200 notifications (seems to be a magic number after trial and error). Since we introduced that feature (along with some other minor comlink recovery options), the failed notification rate for large amounts of notifications went to zero.




回答3:


Same problem.. It looks like a limit of 2000 devices is the maximum. So, 2000 (or less) tokens by socket opened. Try and see !



来源:https://stackoverflow.com/questions/6819315/max-number-of-devices-to-send-to-apns-socket-sever

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!