使用gcm和php向80k及以上用户调度推送通知

使用gcm和php向80k及以上用户调度推送通知,php,cron,google-cloud-messaging,Php,Cron,Google Cloud Messaging,首先,我检查数据库表,查找不同用户发布的未发送消息。如果可用,则执行以下代码,并使用cron作业每5分钟运行一次 SELECT * FROM `jkeio_community_gcmusers`; //contain all gcm users $i=0; while($data_apps=mysql_fetch_array($data_app)) { $message1=$i.'You have a new item in Akhbar'; sendnotificati

首先,我检查数据库表,查找不同用户发布的未发送消息。如果可用,则执行以下代码,并使用cron作业每5分钟运行一次

SELECT * FROM `jkeio_community_gcmusers`; //contain all gcm users
$i=0;

while($data_apps=mysql_fetch_array($data_app))
         {
 $message1=$i.'You have a new item in Akhbar';
 sendnotificationandroid($data_apps['gcm_regid'],$message1); //send function for sending push notification for android and it sends message via curl method
$i++;

             }
发送消息后,我将使用更新查询将unsent标志设置为sent

对于100或200个用户来说,一切都没问题,但当用户增加时,消息就会按时发送 你能建议我如何做到这一点吗

提前谢谢
Anand Neema

GCM允许我们一次向多达1000台设备发送通知,因此我建议重构您的方法
sendnotificationandroid
,以接受GCM注册ID数组

例如,您可以首先遍历数据库行,收集注册表ID并将其附加到数组中。一旦数组大小达到1000(或不再需要添加注册ID),将其传递给新的
sendnotificationandroid
方法,该方法将构建如下通知负载:

{
  "registration_ids" : ["regId1", "regId2", "regId3", ....., "regId1000"],
  "data" : {
    ...
  },
}

因此,对于80K用户,您需要大约80个循环来发送通知,正如Alma Do Mundo所建议的,最好使用curl_multi_exec将请求发送到GCM服务器。

不要在发布的代码中使用mysql函数,因为它们已被正式弃用。至于你的问题,我想卷发可以解决