I currently have an app configured to send push notification via Google/GCM. This is working fine, however there is a 1000 limit per push notification. Currently, I have to loop the registration ID's into separate messages and send them in batches. My question is, I am not very familiar with CURL. How can I utilize curl_mutli_exec to speed up the push notifications and get messages to users with less of a delay.
Here is the current way I have it set up. What do I need to do to utilize curl_mutli_exec? Thanks!
$file = fopen("/gcmusers.key", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
$pcount = 0;
$registrationIDs = array();
while(!feof($file)) {
$pid = fgets($file);
$pcount = $pcount + 1;
if ($pid <> '') {
array_push($registrationIDs,$pid);
}
if ($pcount == 990) {
// Message to be sent
$apiKey = "MyAPIKEY";
$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registration_ids' => $registrationIDs, 'data' => array( "message" => $message, "pic" => $pic, "price" => $price, "item" => $item, "site" => $site, "refurb" => $refurb, "percent" => $percent, "buyurl" => $buyurl ),);
$headers = array('Authorization: key=' . $apiKey, '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 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
$registrationIDs = array();
$pcount = 0;
}
}