title: Send Push Notification to multiple tokens with PHP (iOS)
body: <p>I've a database with all the devicetokens. I proceed to pick up the tokens from the database, but my script doens't work then anymore (the pushes don't send). </p>
  
  <p>This is my script:</p>
  
  <pre><code>&lt;?PHP
  
  $db_user = "xxx"; // Gebruiker voor MySQL
  $db_pass = "xxx"; // Wachtwoord voor MySQL
  $db_host = "localhost"; // Host voor MySQL; standaard localhost
  $db_db = "xxx"; // Database
  
  // Als je al ergens anders een database connectie hebt gemaakt,
  // maak dan van de volgende twee regels commentaar (# of // ervoor zetten)
  mysql_connect($db_host,$db_user,$db_pass);
  mysql_select_db($db_db);
  
  $query = mysql_query("SELECT * FROM iospush");
  
                                  while ($row = mysql_fetch_array($query)) {
                                      $deviceToken = $row["devicetoken"];
                                      }
  
  if($_POST['message']){
  
  //  $deviceToken = 'xxx';
  
      $message = stripslashes($_POST['message']);
  
      $payload = '{
                      "aps" : 
  
                          { "alert" : "'.$message.'",
  "badge" : 1
                          } 
                  }';
  
  
      $ssl='xx.pem';
  
      $ctx = stream_context_create();
      stream_context_set_option($ctx, 'ssl', 'local_cert', $ssl);
      stream_context_set_option($ctx, 'ssl', 'passphrase', 'xxx');
      $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
      if(!$fp){
          print "Failed to connect $err $errstrn";
          return;
      } else {
          print "Notifications sent!";
      }
  
      $devArray = array();
      $devArray[] = $deviceToken;
  
      foreach($devArray as $deviceToken){
          $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack        ("n",strlen($payload)) . $payload;
          print "sending message :" . $payload . "n";
  
          fwrite($fp, $msg);
      }
      fclose($fp);
  }
  
  ?&gt;
  &lt;form action="pushios.php" method="post"&gt;
      &lt;input type="text" name="message" maxlength="100"&gt;
      &lt;input type="submit" value="Send Notification"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Please help me to make this working!</p>
  
  <p>Thanks in regard!</p>