如何使用GCM在php中向数百万android设备发送通知
我是安卓应用程序的新开发者。我使用GCM从PHP代码向android设备发送通知。我制作了一个包含所有设备ID和send的数组,但问题是当我发送一千多个设备时。我发现内部服务器错误。我的代码在下面如何使用GCM在php中向数百万android设备发送通知,php,curl,push-notification,google-cloud-messaging,Php,Curl,Push Notification,Google Cloud Messaging,我是安卓应用程序的新开发者。我使用GCM从PHP代码向android设备发送通知。我制作了一个包含所有设备ID和send的数组,但问题是当我发送一千多个设备时。我发现内部服务器错误。我的代码在下面 function _send_notification($registatoin_ids = '', $message = '') { $url = 'https://android.googleapis.com/gcm/send'; $fields = array(
function _send_notification($registatoin_ids = '', $message = '') {
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
//pr($fields);
$headers = array(
'Authorization: key=' . $this->GOOGLE_API_KEY,
'Content-Type: application/json',
'Connection: keep-alive',
'Keep-Alive: 300'
);
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
//curl_setopt($ch, CURLOPT_CONNECT_ONLY, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10000); // drop connection after 10000 seconds
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
// Close connection
curl_close($ch);
return $result; //exit;
}
请帮帮我您最多可以发送1000个注册ID。您需要将其分解为多个curl调用,每个调用都有1k个注册ID的分组
function _send_notification($registration_ids = '', $message = '') {
$url = 'https://android.googleapis.com/gcm/send';
$groups = array_chunk($registration_ids, 1000);
foreach($groups as $group) {
$fields = array(
'registration_ids' => $group,
'data' => $message,
);
// ...
// rest of your curl code
}
}
您最多可以发送1000个注册ID。您需要将其分解为多个curl调用,每个调用都有1k个注册ID的分组
function _send_notification($registration_ids = '', $message = '') {
$url = 'https://android.googleapis.com/gcm/send';
$groups = array_chunk($registration_ids, 1000);
foreach($groups as $group) {
$fields = array(
'registration_ids' => $group,
'data' => $message,
);
// ...
// rest of your curl code
}
}
谢谢我正在做这件事,但仍然有一个超时问题。如果我减少到250,那么它就会工作。但是如果我有超过一百万的用户,那么会有同样的超时问题谢谢。。。我正在做这件事,但仍然有一个超时问题。如果我减少到250,那么它就会工作。但是如果我有超过一百万的用户,那么就会出现同样的超时问题