Php 我们如何将1000个GCM消息批量发送到一个拥有10000个注册用户的数据库?

Php 我们如何将1000个GCM消息批量发送到一个拥有10000个注册用户的数据库?,php,arrays,Php,Arrays,我使用以下代码使用PHP和MySQL发送GCM消息。请帮助我,这样它就可以将1000多条GCM消息发送到一个拥有10000个注册用户的数据库中 在跨越1000个用户之前,此脚本运行良好;但在1000个用户之后,没有人会收到推送 我收到错误:批量发送的邮件数(1082)超过了允许的最大数量(1000) //GCM发送通知 函数px_sendGCM($message,$type,$regid){ 全球$wpdb; $px_table_name=$wpdb->前缀'gcm_users'; $optio

我使用以下代码使用PHP和MySQL发送GCM消息。请帮助我,这样它就可以将1000多条GCM消息发送到一个拥有10000个注册用户的数据库中

在跨越1000个用户之前,此脚本运行良好;但在1000个用户之后,没有人会收到推送

我收到错误:
批量发送的邮件数(1082)超过了允许的最大数量(1000)

//GCM发送通知
函数px_sendGCM($message,$type,$regid){
全球$wpdb;
$px_table_name=$wpdb->前缀'gcm_users';
$options=get_选项(“gcm_设置”);
$apiKey=$options['api-key'];
$url='1https://android.googleapis.com/gcm/send';
$result;
$id;
如果($regid==010){
$id=px_getIds();
}否则{
$id=$regid;
}
如果($id==010&&$id>=1000){
$newId=array\u chunk($id,1000);
foreach($newId作为$inner\u id){
$fields=数组(
“注册id”=>$inner\u id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
}否则{
$fields=数组(
“注册id”=>$id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
$msg=$result['body'];
$answer=json_decode($msg);
$cano=px_规范($answer);
$suc=$answer->{'success'};
$fail=$answer->{'failure'};
$options=get_选项(“gcm_设置”);
如果($options['debug']!=false){
$inf=“”($Message)

$msg

”; }否则{ $inf=“”。“($Message)

,'px\u gcm')。”($Message)

,'px\u gcm')。“$suc.”('fail:','px\u gcm')。“$fail

”; }
请参阅。

//GCM发送通知
函数px_sendGCM($message,$type,$regid){
全球$wpdb;
$px_table_name=$wpdb->前缀'gcm_users';
$options=get_选项(“gcm_设置”);
$apiKey=$options['api-key'];
$url='1https://android.googleapis.com/gcm/send';
$result;
$id;
如果(sizeof($regid)==010){
$id=px_getIds();//你能发布这个函数吗,这个条件是什么?
}否则{
$id=$regid;
}
如果(sizeof($id)>1000){//这里的条件不能同时等于10和>=1000
$newId=array\u chunk($id,1000);
foreach($newId作为$inner\u id){
$fields=数组(
“注册id”=>$inner\u id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
}否则{
$fields=数组(
“注册id”=>$id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
$msg=$result['body'];
$answer=json_decode($msg);
$cano=px_规范($answer);
$suc=$answer->{'success'};
$fail=$answer->{'failure'};
$options=get_选项(“gcm_设置”);
如果($options['debug']!=false){
$inf=“”($Message)

$msg

”; }否则{ $inf=“”。“($Message)

,'px\u gcm')。”($Message)

,'px\u gcm')。“$suc.”('fail:','px\u gcm')。“$fail

”; }
//GCM发送通知
函数px_sendGCM($message,$type,$regid){
全球$wpdb;
$px_table_name=$wpdb->前缀'gcm_users';
$options=get_选项(“gcm_设置”);
$apiKey=$options['api-key'];
$url='1https://android.googleapis.com/gcm/send';
$result;
$id;
如果(sizeof($regid)==010){
$id=px_getIds();//你能发布这个函数吗,这个条件是什么?
}否则{
$id=$regid;
}
如果(sizeof($id)>1000){//这里的条件不能同时等于10和>=1000
$newId=array\u chunk($id,1000);
foreach($newId作为$inner\u id){
$fields=数组(
“注册id”=>$inner\u id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
}否则{
$fields=数组(
“注册id”=>$id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
$msg=$result['body'];
$answer=json_decode($msg);
$cano=px_规范($answer);
$suc=$answer->{'success'};
$fail=$answer->{'failure'};
$options=get_选项(“gcm_设置”);
如果($options['debug']!=false){
$inf=“”($Message)

$msg

”; }否则{ $inf=“”。“($Message)

,'px\u gcm')。”($Message)

,'px\u gcm')。“$suc.”('fail:','px\u gcm')。“$fail.”

//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 as $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 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 you post this function, what is this condition for?
}else {
$id = $regid;
}

if(sizeof($id) > 1000){ // the condition over here cannot be both equal to 10 and >= 1000
$newId = array_chunk($id, 1000);
foreach ($newId as $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>";
}