title: APNS multiple registerId's
body: <p>My App is using APNS push. Now I read that you can leave the connection open while sending multiple messages. So reason enough for me to change some scripts. </p>
  
  <p>My APNS class has the following methods(and many more, but these are the most important for now): </p>
  
  <pre><code>public function setRegisterId($registerId){
      $this-&gt;registerId = $registerId;
  }
  
  public function setupConnection()
  {
      $APNSdetails[1] = array('pemFile'=&gt;'test.pem', 'passPhrase'=&gt;'passPhrase');
      $APNSdetails[2] = array('pemFile'=&gt;'mag.pem', 'passPhrase'=&gt;'passPhrase');
  
      $ctx = stream_context_create();
      stream_context_set_option($ctx, 'ssl', 'local_cert', '/as/'.$APNSdetails[$this-&gt;appId]['pemFile']);
      stream_context_set_option($ctx, 'ssl', 'passphrase', $APNSdetails[$this-&gt;appId]['passPhrase']);
  
      // Open a connection to the APNS server
      $this-&gt;connection = stream_socket_client(
              'ssl://gateway.push.apple.com:2195', $err,
              $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
  
      if (!$this-&gt;connection){
          return FALSE;
      }
      else{
          return TRUE;
      }
  }
  
  public function sendMessage()
  {
      $RegisterIds = $this-&gt;registerId;
      foreach ($RegisterIds AS $key =&gt; $value){
  
          // Build the binary notification
          $msg = chr(0) . pack('n', 32) . pack('H*', $RegisterIds[$key]['registerId']) . pack('n', strlen($this-&gt;payload)) . $this-&gt;payload;
  
          // Send it to the server
          $result = fwrite($this-&gt;connection, $msg, strlen($msg));
  
          $RegisterIds[$key]['payload'] = $this-&gt;payload;
  
          if (!$result){
              $RegisterIds[$key]['result'] = 'Message not delivered';
          }
          else{
              $RegisterIds[$key]['result'] = 'Message successfully delivered';
          }
      }
  
      $this-&gt;results = $RegisterIds;
  }
  </code></pre>
  
  <p>Now I'm testing the script with some user typed data: (i've removed last 6 characters of registerId, for safety purposes). Using this array, both devices are receiving the Push Message. </p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [registerId] =&gt; ddbb8b9b27beed70e56866d07a3da5f4cabf71ffab4606967a523e93eb
              [id] =&gt; 214
              [deviceOs] =&gt; apple
          )
  
      [1] =&gt; Array
          (
              [registerId] =&gt; c20f10e0b7f345988440d860bfb179f5b95a47d7eee714f5e0268c2c93
              [id] =&gt; 234
              [deviceOs] =&gt; apple
          )
  
  )
  </code></pre>
  
  <p>Using a query to retrieve other (more real live) data provided with the following array:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [registerId] =&gt; 165ad6daa6e6e2c470d1c2777901e731f34fbe419f7d93cda383665c39
              [id] =&gt; 1111
              [deviceOS] =&gt; apple
          )
  
      [1] =&gt; Array
          (
              [registerId] =&gt; ddbb8b9b27beed70e56866d07a3da5f4cabf71ffab4606967a523e93eb
              [id] =&gt; 1328
              [deviceOS] =&gt; apple
          )
  
      [2] =&gt; Array
          (
              [registerId] =&gt; 7383d29d4bc210b32ea409e46a99ca522a3cf4a51e330f7d7457f7bc88
              [id] =&gt; 359
              [deviceOS] =&gt; apple
          )
  
      [3] =&gt; Array
          (
              [registerId] =&gt; c20f10e0b7f345988440d860bfb179f5b95a47d7eee714f5e0268c2c93
              [id] =&gt; 1148
              [deviceOS] =&gt; apple
          )
  
  )
  </code></pre>
  
  <p>As you can see that are 2 the same registerId's and 2 new registerId's. However, none of the 4 devices is receiving a push notification. </p>
  
  <p>I'm, kind of stuck or lost... Why is the second array failing? </p>