php - 1000 User GCM: Array to String Conversion Error -
i attempting send batched gcm messages in blocks of 1000. however, below code returns error array string conversion in c:\xampp\htdocs\index.php on line 651
on line: echo updatedatagcm($db);
within action:
case "sendgroupmessage": if ($userid = authenticateuser($db, $username, $password, $gcmregid)) { if (isset($_request['togroupid'])) { // instead of tousername it's groupid $togroupname = $_request['togroupname']; $togroupid = $_request['togroupid']; $message = $_request['messagetext']; $campaign = $_request['campaign_id']; $location = $_request['location_id']; // query users id's in group not user sending message $sqlgroupmembers = "select distinct usersid users_groups usersid != '".$userid."' , groupid = '".$togroupid."'"; // loop create copy of message users taht part of group if($getgroupmembersid = $db->query($sqlgroupmembers)) { while($rowgroupmembers = $db -> fetchobject($getgroupmembersid)) { $sql22 = "insert `group_messages`..."; error_log("$sql22", 3 , "error_log"); if ($db->query($sql22)) { $out = successful; } else { $out = failed; } } } // send gcm turn on devices: echo updatedatagcm($db); } else { $out = failed; } } else { $out = failed; } break;
the updatedatagcm() function:
function updatedatagcm($db) { // gcm regids new, "unseen" data: $sqlallregids = 'select distinct gcm_registration_id users'; // execute if ($resultids = $db->query($sqlallregids)) { $gcmregids = array(); $i = 0; while($query_row = $db -> fetchobject($resultids)) { $i++; $gcmregids[floor($i/1000)][] = $query_row; } $pushmessage = $_post["syncnewdata"]; $message = array("syncnewdata" => $pushmessage); $pushstatus = array(); foreach($gcmregids $val) $pushstatus[] = sendpushnotificationtogcm($val, $message); return $pushstatus; } }
how can send gcm messages properly?
nothing in code indicates gcm isn't sending properly; can't there.
however, indicating you're trying echo return value of updatedatagcm
function array $pushstatus;
you've returned function return $pushstatus;
.
in order know you're working with, should use gettype($var)
, , var_dump($var);
@ minimum.
sidenote
you should have read making of google cloud messaging. there things such rate limits, quality control, may impede ability send out 1000's of gcm's (which self doesn't make sense.)