title: Sending GCM Notification to 100 000 users with a PHP script
body: <p>I have a GCM Notifications based app,everytime a new user installs app its GCM registration id is stored on the php server's mysql database , now I have written a script to send notification to all registered users as follows </p>
  
  <pre><code>&lt;?php
  
  //------------------------------
  // Payload data you want to send 
  // to Android device (will be
  // accessible via intent extras)
  //------------------------------
  
  
  //------------------------------
  // The recipient registration IDs
  // that will receive the push
  // (Should be stored in your DB)
  // 
  // Read about it here:
  // http://developer.android.com/google/gcm/
  //------------------------------
  
  if(isset($_GET['message'])) 
  {
  
      $msg = $_GET['message'];
      $data = array("price" =&gt; $msg);
      $ids = array();
      require_once dirname(__FILE__). '/db_connect.php';;
      $db = new DB_CONNECT();
      $qry = mysql_query("SELECT gcm_regid FROM gcm_users");
  
  
  
      while($row = mysql_fetch_array($qry))
      {
          $ids[] = $row['gcm_regid'];
      }
  
  //$ids = array( 'abc', 'def' );
  
  //------------------------------
  // Call our custom GCM function
  //------------------------------
  
  
  //------------------------------
  // Define custom GCM function
  //------------------------------
  
  function sendGoogleCloudMessage( $data, $ids )
  {
      //------------------------------
      // Replace with real GCM API 
      // key from Google APIs Console
      // 
      // https://code.google.com/apis/console/
      //------------------------------
  
      $apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
  
      //------------------------------
      // Define URL to GCM endpoint
      //------------------------------
  
      $url = 'https://android.googleapis.com/gcm/send';
  
      //------------------------------
      // Set GCM post variables
      // (Device IDs and push payload)
      //------------------------------
  
      $post = array(
                      'registration_ids'  =&gt; $ids,
                      'data'              =&gt; $data,
                      );
  
      //------------------------------
      // Set CURL request headers
      // (Authentication and type)
      //------------------------------
  
      $headers = array( 
                          'Authorization: key='. $apiKey,
                          'Content-Type: application/json'
                      );
  
      //------------------------------
      // Initialize curl handle
      //------------------------------
  
      $ch = curl_init();
  
      //------------------------------
      // Set URL to GCM endpoint
      //------------------------------
  
      curl_setopt( $ch, CURLOPT_URL, $url );
  
      //------------------------------
      // Set request method to POST
      //------------------------------
  
      curl_setopt( $ch, CURLOPT_POST, true );
  
      //------------------------------
      // Set our custom headers
      //------------------------------
  
      curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers );
  
      //------------------------------
      // Get the response back as 
      // string instead of printing it
      //------------------------------
  
      curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
  
      //------------------------------
      // Set post data as JSON
      //------------------------------
  
      curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post ) );
  
      //------------------------------
      // Actually send the push!
      //------------------------------
  
      $result = curl_exec( $ch );
  
      //------------------------------
      // Error? Display it!
      //------------------------------
  
      if ( curl_errno( $ch ) )
      {
          echo 'GCM error: ' . curl_error( $ch );
      }
  
      //------------------------------
      // Close curl handle
      //------------------------------
  
      curl_close( $ch );
  
      //------------------------------
      // Debug GCM response
      //------------------------------
  
      echo $result;
  }
  sendGoogleCloudMessage(  $data, $ids );
  
  }
  ?&gt;
  </code></pre>
  
  <p>My worry is that when the user base will be huge then the script might fail.</p>