android - Using curl_multi_exec with gcm push notifications and PHP -
i have app configured send push notification via google/gcm. working fine, there 1000 limit per push notification. currently, have loop registration id's separate messages , send them in batches. question is, not familiar curl. how can utilize curl_mutli_exec speed push notifications , messages users less of delay.
here current way have set up. need utilize curl_mutli_exec? thanks!
$file = fopen("/gcmusers.key", "r") or exit("unable open file!"); //output line of file until end reached $pcount = 0; $registrationids = array(); while(!feof($file)) { $pid = fgets($file); $pcount = $pcount + 1; if ($pid <> '') { array_push($registrationids,$pid); } if ($pcount == 990) { // message 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 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; } }
Comments
Post a Comment