php - how to fix GCM 1000 message limit,want to send message to a database of 10000? -


i using following code send gcm messages using php , mysql. please me out can send gcm messages in lots of 1000 database of 10,000 registered users.

before crossing 1000 users, script worked fine; after 1000 users, no 1 receives push error received script "number of messages on bulk (1082) exceeds maximum allowed (1000) "

//gcm send notification function px_sendgcm($message, $type, $regid) { global $wpdb; $px_table_name = $wpdb->prefix.'gcm_users'; $options = get_option('gcm_setting'); $apikey = $options['api-key']; $url = 'https://android.googleapis.com/gcm/send'; $result; $id;  if($regid == 010) { $id = px_getids(); }else { $id = $regid; }  if($id == 010 && $id >= 1000){ $newid = array_chunk($id, 1000); foreach ($newid $inner_id) {     $fields = array(         'registration_ids' => $inner_id,         'data' => array($type => $message)      );      $headers = array(         'authorization' => 'key=' . $apikey,         'content-type' => 'application/json'     );      $result = wp_remote_post($url, array(         'method' => 'post',         'headers' => $headers,         'httpversion' => '1.0',         'sslverify' => false,         'body' => json_encode($fields) )     ); } }else { $fields = array(     'registration_ids' => $id,     'data' => array($type => $message) );  $headers = array(     'authorization' => 'key=' . $apikey,     'content-type' => 'application/json' );  $result = wp_remote_post($url, array(     'method' => 'post',     'headers' => $headers,     'httpversion' => '1.0',     'sslverify' => false,     'body' => json_encode($fields))     );     }  $msg = $result['body']; $answer = json_decode($msg); $cano = px_canonical($answer); $suc = $answer->{'success'}; $fail = $answer->{'failure'}; $options = get_option('gcm_setting'); if($options['debug'] != false){ $inf= "<div id='message' class='updated'><p><b>".__('message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>$msg</p></div>"; }else { $inf= "<div id='message' class='updated'><p><b>".__('message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>".__('success:','px_gcm')." $suc  &nbsp;&nbsp;".__('fail:','px_gcm')." $fail </p></div>"; } 

gcm allows send 1000 messages in single request. if want send messages more 1000 customers, use loop call function px_sendgcm($message, $type, $regid) every 1000 customers

your code should be:

//gcm send notification function px_sendgcm($message, $type, $regid) { global $wpdb; $px_table_name = $wpdb->prefix.'gcm_users'; $options = get_option('gcm_setting'); $apikey = $options['api-key']; $url = 'https://android.googleapis.com/gcm/send'; $result; $id;  if(sizeof($regid) == 010) { $id = px_getids(); //can post function, condition for? }else { $id = $regid; }  if(sizeof($id) > 1000){ $newid = array_chunk($id, 1000); foreach ($newid $inner_id) {     $fields = array(         'registration_ids' => $inner_id,         'data' => array($type => $message)      );      $headers = array(         'authorization' => 'key=' . $apikey,         'content-type' => 'application/json'     );      $result = wp_remote_post($url, array(         'method' => 'post',         'headers' => $headers,         'httpversion' => '1.0',         'sslverify' => false,         'body' => json_encode($fields) )     ); } }else { $fields = array(     'registration_ids' => $id,     'data' => array($type => $message) );  $headers = array(     'authorization' => 'key=' . $apikey,     'content-type' => 'application/json' );  $result = wp_remote_post($url, array(     'method' => 'post',     'headers' => $headers,     'httpversion' => '1.0',     'sslverify' => false,     'body' => json_encode($fields))     );     }  $msg = $result['body']; $answer = json_decode($msg); $cano = px_canonical($answer); $suc = $answer->{'success'}; $fail = $answer->{'failure'}; $options = get_option('gcm_setting'); if($options['debug'] != false){ $inf= "<div id='message' class='updated'><p><b>".__('message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>$msg</p></div>"; }else { $inf= "<div id='message' class='updated'><p><b>".__('message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>".__('success:','px_gcm')." $suc  &nbsp;&nbsp;".__('fail:','px_gcm')." $fail </p></div>"; } 

Comments