title: Apple Push Notification: Sending high volumes of messages
body: <p>I am using PHP to connect to <code>apn</code>s to send some notifications to multiple devices, although the question is more conceptual so it doesn't have to be specific to PHP.</p>
  
  <p>I will be sending to about 7000 devices (and growing) all at the same time.
  My process runs ONCE per day and broadcasts to all devices, so I am not constantly re-opening a connection.</p>
  
  <p>Currently I can easily send to 2 devices at a time and the messages will successfully deliver.
  However when I attempt to send to the full 7000 devices, the messages do not seem to deliver.</p>
  
  <p>The pseudo-logic to my code is:</p>
  
  <pre><code>open connection to apple
  loop over device-tokens
      write to socket connection per device
  end loop
  close connection to apple.
  </code></pre>
  
  <p>I have seen somewhere that I should only perform a SINGLE write, and construct one huge body, in other words the pseudo-code would look like:</p>
  
  <pre><code>loop over device tokens
      create payload aggregating all devices
  end loop
  open connection to apple
  write to socket ONCE with whole payload for 7000 devices
  close connection
  </code></pre>
  
  <p>It's difficult to test as I obviously can't spam my 7000 production users with test messages.
  Has anybody else had a similar problem?</p>
  
  <p>Thanks</p>