title: how to send iPhone Push Notification to Multiple Devices.?
body: <p>I am getting a device token from database, but the notification which is sent successfully, its just receiving to the latest device in database. </p>
  
  <p>But I have 3 devices tokens in my database.</p>
  
  <pre><code>if (!$fp)
      exit("Failed to connect: $err $errstr" . PHP_EOL);
  echo 'Connected to APNS' . PHP_EOL;
  // Create the payload body
  $body['aps'] = array(
      'alert' =&gt; $message,
      'badge' =&gt; 1,
      'sound' =&gt; 'default'
      );
  // Encode the payload as JSON
  $payload = json_encode($body);
  // Build the binary notification
  $result = mysql_query("SELECT DeviceToken FROM iOS");
  while($row = mysql_fetch_array($result))
  {
      $deviceToken=$row['DeviceToken'];   
      echo $deviceToken;
      $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
  }
  // Send it to the server
  $result = fwrite($fp, $msg, strlen($msg));
  if (!$result)
      echo 'Message not delivered' . PHP_EOL;
  else
      echo 'Message successfully delivered '.PHP_EOL;
  // Close the connection to the server
  fclose($fp);
  echo "&lt;script&gt;alert('Notification Sent Successfuly!'); location.href='Pushnotification.php';&lt;/script&gt;";
  </code></pre>