title: send gcm message in groups of 1000 users to all 10000 users
body: <p>i am using following code to send gcm message using php and mysqldb i have successfully send the gcm message and received it on the device however the android guidelines state that gcm message should be send in batch of 1000 each <a href="http://developer.android.com/training/cloudsync/gcm.html#multicast" rel="nofollow">http://developer.android.com/training/cloudsync/gcm.html#multicast</a></p>
  
  <p>now my question is how can we send gcm messages in lots of 1000 to a database of say 10,000 registered users.</p>
  
  <pre><code>&lt;?php
  require 'connect.php';
  
  function sendPushNotification($registration_ids, $message) {
  
      $url = 'https://android.googleapis.com/gcm/send';
      $fields = array(
          'registration_ids' =&gt; $registration_ids,
          'data' =&gt; $message,
      );
  
      define('GOOGLE_API_KEY', 'keys_value');
  
      $headers = array(
          'Authorization:key=' . GOOGLE_API_KEY,
          'Content-Type: application/json'
      );
      echo json_encode($fields);
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  
      $result = curl_exec($ch);
      if($result === false)
          die('Curl failed ' . curl_error());
  
      curl_close($ch);
      return $result;
  
  }
  
  $pushStatus = '';
  
  if(!empty($_GET['push'])) {
  
      $query = "SELECT gcm_regId FROM gcm_users";
      if($query_run = mysql_query($query)) {
  
          $gcmRegIds = array();
          while($query_row = mysql_fetch_assoc($query_run)) {
  
              array_push($gcmRegIds, $query_row['gcm_regId']);
  
          }
  
      }
      $pushMessage = $_POST['message'];
      if(isset($gcmRegIds) &amp;&amp; isset($pushMessage)) {
  
          $message = array('price' =&gt; $pushMessage);
          $pushStatus = sendPushNotification($gcmRegIds, $message);
  
      }   
  }
  
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Google Cloud Messaging (GCM) Server in PHP&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;h1&gt;Google Cloud Messaging (GCM) Server in PHP&lt;/h1&gt;
      &lt;form method = 'POST' action = 'send_all.php/?push=1'&gt;
          &lt;div&gt;
              &lt;textarea rows = 2 name = "message" cols = 23 placeholder = 'Messages to Transmit via GCM'&gt;&lt;/textarea&gt;
          &lt;/div&gt;
          &lt;div&gt;
              &lt;input type = 'submit' value = 'Send Push Notification via GCM'&gt;
          &lt;/div&gt;
          &lt;p&gt;&lt;h3&gt;&lt;?php echo $pushStatus ?&gt;&lt;/h3&gt;&lt;/p&gt;
      &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>