How to send notification for more than 1000 users using GCM

I have a PHP code that sends notification to users but suddenly it has been stopped as I reached 1000 users so I shall send 1000 by 1000. Please tell me how to modify my code to do that?

function send_notification($custom_message) { global $GOOGLE_API_KEY; global $message; // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; // Get comments data from comments table $query = "SELECT gcm_regid FROM tbl_gcm_users"; $result = $this->mysqli->query($query); $regids = array(); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $regids[] = $row['gcm_regid']; } if (empty($custom_message)) { $message_arr = array("message" => $message); } else { $message_arr = array("message" => $custom_message); } $fields = array( 'registration_ids' => $regids, 'data' => $message_arr, ); $headers = array( 'Authorization: key=' . $GOOGLE_API_KEY, 'Content-Type: application/json' ); // Open connection $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); // 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; }

I have tried the following code but it send the notification to the latest users chunk only not all the users.

function send_notification($custom_message) { global $GOOGLE_API_KEY; global $message; // Set POST variables $url = 'https://android.googleapis.com/gcm/send'; // Get comments data from comments table $query = "SELECT gcm_regid FROM tbl_gcm_users"; $result = $this->mysqli->query($query); $regids = array(); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { $regids[] = $row['gcm_regid']; } $regIdChunk=array_chunk($regids,1000); foreach($regIdChunk as $RegId){ if (empty($custom_message)) { $message_arr = array("message" => $message); } else { $message_arr = array("message" => $custom_message); } $fields = array( 'registration_ids' => $RegId, 'data' => $message_arr, ); $headers = array( 'Authorization: key=' . $GOOGLE_API_KEY, 'Content-Type: application/json' ); // Open connection $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); // 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; }

Category:notifications Views:0 Time:2018-12-05

Related post

  • Shared Excel File - Read\Write access for more than one user in the same time 2014-08-01

    Hi .. I shared one excel file with many users , each user has read\write access lonely on specific cells. How can I enable more than one user to access the same file with read\write access for each one of them ? Thanks --------------Solutions--------

  • How to send the SMS more than 160 character? 2011-07-05

    How to send big SMS in android. I used : SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(contactNos[j], null,msgs[i], sentPI, deliveredPI); this code work only for 160 character message. i also use ArrayList<String> msgsplit=sms.d

  • Codeigniter Generate PDF for more than 1000 rows 2011-06-11

    I have tried generate PDF file from CodeIgniter using PHPExcel, mPDF, TCPDF and HTML2PDF but there was a problem for generating more than 1000 rows fetching from MySQL. The problem start from memory exhausted also my xampp server needed to restart. P

  • Getting error when sending mail to more than one address using SKPSMTPMessage 2009-07-28

    I am getting error when i am trying to send mail to more than one email address using AOL account in SKPSMTPMESSAGE api. I can send with one receiver but i can send to more than one receiver. Getting message like "To address rejected". Does anyone ha

  • How to create PagePreview with more than one page using PDFSharp? 2009-10-23

    I am using PDFSharp to create PDF files in my C# application. It's working very good, but i did not find out how to create preview with more than one page. I have no trouble creating and saving document with multiple pages, also embedding PagePreview

  • How to enable chat(private chat) with more than one user using smack 2011-04-17

    I am able to connect to gtalk and facebook server.I can also get the presence of users.Right now I can chat with one person at a time.But I want to chat with more than one users at a time(private chat) Is it possible to have private chat with more th

  • How to make a paragraph more than one line using xsl 2011-09-13

    In a paragraph i should have more than one line it should be like 3 line or more,but not just one like and one another thing is i need to remove '...', '…' and replace it with just period. I need to added period for each sentence after ... in xsl, an

  • PHP check password script wont work for more than one user 2012-04-22

    I am trying to create a simple login credentials checker (with session variables). this is what i have so far: <?php include("dbconnect.php"); $u_name = mysql_real_escape_string($_POST['uname']); $p_word = mysql_real_escape_string($_POST['pword'])

  • How to error check for more than a certain amount of Command Parameters 2011-07-13

    I'm not quite sure how to google search this or put it into one sentence but here is my scenario. I am creating a simple program in C# that one feature of it is to take command parameters and to get a directory from a certain command parameter and an

  • How to share 1 certificate for more than 1 user 2013-08-13

    I ahve 1 certificate and i would like to share this certificate amongst other users. Can can this be setup for all profiles or users who log into the one PC? --------------Solutions------------- A certificate for what? its a certificate for some thir

  • Cannot send emails to more than 10 users with attachment by using Window Live Mail 2014-11-05

    Question Summary Other Windows Live ID issues Please provide your impacted Email address : *** Email address is removed for privacy *** Additional Details My boss's account account "*** Email address is removed for privacy ***" (hosted by Link dot Ne

  • set up for more than one user 2013-06-07

    Our whole family will be using computer. How do we view individual emails and other information from the start screen? --------------Solutions------------- Hi Frank, I suggest you to create different user accounts for each member in the family and th

  • How to send email with more than one attachments in classic ASP? 2010-04-05

    how to attach more then one files and then send mail using ASP Technology.. Not with ASP.NET so please guide me.. and I want to send this mail when page load... so where should I write... Thanks in advance --------------Solutions------------- To send

  • How to write CellForRowAtIndex for more than one uitableview on single uiview 2011-08-10

    I am trying to load three uitableview on my uiview so i am getting the data on first uitableview but how can i write datasource code for ohter two as there is only one datasource method of uitableview i.e CellForRowAtIndex . If any one has solution o

  • How to sync settings for more than one computer 2012-04-05

    I am using the sync feature of Windows 8 to store things like my desktop background, and settings for start menu. Of course I only have one Microsoft account and I am using it (the email + passwort) login on every PC with Windows 8 I have. And here c

  • Waiting for more than one event (using GWT) 2011-02-23

    I want to fetch two XML documents from the server and resume processing when both have arrived. Can I fetch them in parallel, or do I have to refrain from issuing the second request until the first has completed? --------------Solutions-------------

  • how to access Outlook from more than one user on a pc 2014-03-31

    I have Outlook 2013 on windows 8, I have a desktop with two users, office with outlook was installed under user1 and works fine. however when I try and start outlook as user2 it goes looking for user1's files for some reason rather than going to setu

  • Can i increase my weblogic 8 license for more than 3 user 2010-12-20

    I am using weblogic 8 in my project. My deployed folder is accessed by only 3 user simultaneously. fourth user is unable to access that url. and getting 403 error. Error is: The Server is not licensed for this operation. What is the solution for this

  • Failed to populate Facebook send dialog with more than 1 recipient using Javascript SDK 2011-10-20

    I've struggled with this issue for the past 3 hrs and googled/SO a ton of links. Sample code: <script> FB.ui({ method: 'send', picture: window.location.protocol + '//' + window.location.host + '/i/fb3.png', name: 'XX', description: 'Blah blah b

  • Searching for more than one user 2011-10-13

    I would like to use Graph API to search for users whose names are "John" or "Mark". https://graph.facebook.com/search?q=john&type=user https://graph.facebook.com/search?q=mark&type=user Is it possible to receive those informations using only

  • jQuery not replacing html button with text for more than 1 user 2011-10-25

    I have this piece of code written in jQuery and PHP: <script type="text/javascript"> $(document).ready(function(){ $(".vote<?php echo $pid; ?>").click(function(){ $("span.vote_box<?php echo $pid; ?>").html("you have voted"); }); });

  • Apps for more than one phone use 2014-01-13

    Can I transfer my pais apps to my husbands phone or are they only licenced for one phone use? --------------Solutions------------- The apps are associated with your Live ID so you can't move them to someone elses phone. You can, however, move them to

  • Modern UI display for more than 1 user account. 2015-01-31

    We have 4 users. 2nd user has all the same tiles as mine (administrator) but 3rd has less and the 4th has even less. The 4th user doesn't show an option to have the person app or email app. Is that a possibility? --------------Solutions-------------

  • How do I check if more than one record has been returned from DBI query in Perl? 2009-04-29

    I searched for this on the site already but couldn't locate anything that answered my question. Which brings me to the details: I am querying database using a simple select query, realistically (given the scenario) it should never return more than ab

  • More than one developer using the entity frame 4 .edmx file at any given time 2010-08-10

    I am using EF4. Just a quick question, is this a really good framework? We currently make use of a business and data layer as separate projects. The fact that everything is in 1 file in EF4 is this a good thing? How do you distinguish between your bu

Copyright (C) dskims.com, All Rights Reserved.

processed in 3.756 (s). 12 q(s)