Search code examples
phplinuxpush-notificationapple-push-notificationsbandwidth

Apple Push Notification PHP server bandwidth


I'm planning on launching my first APNS server soon. It's based on PHP and working fine in the test phase. My problem is that im not sure if it can handle 10K or 20K users on a shared server. And to be frank, i cannot figure out how to calculate the exact maximum bandwidth of my server.

Since each payload is 255Bytes, Does it mean sending Notification to 10k users would require 10K*255Bytes bandwidth? Or it just sends a 255Byte packet to apple and apple APNS servers take it from there?

Also, since everytime the app launches we are supposed to get the users device info and token, does this mean a constant high traffic to my server everytime the users open the application?


Solution

    1. 10K*255 is wrong. First of all, the payload limit is 256 bytes, not 255, and that's just the payload. To that you have to add 1 + 4 (message ID) + 4 (expiry) + 2 (token length) + 32 (device token) + 2 (payload length) bytes per notification (assuming you are using the enhanced binary format). This brings you up to 10K*301 bytes. However, that doesn't include any overheads introduced by the TCP protocol itself, so the actual number would be higher.

    2. Even if you send the same payload to all 10K users, you still have to send a copy of that payload along with the other fields for each device separately. That means the bandwidth would be around 10*301Bytes (not counting the TCP overhead).

    3. You don't want to access your server each time a user opens the application. You should ask Apple for a device token each time the app is launched (by registering to push notifications), but you should only send it to your server once, unless it changes. You can check if it changed by storing the device token on the device, and comparing the stored token to the token returns by Apple.