1. Go to this page and download the library: Download stevetauber/php-gcm-queue library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stevetauber / php-gcm-queue example snippets
use \PhpGcmQueue as GCM;
class YourClass {
public function someFunction() {
/* The second param is our class that extends DefaultSendJob.php */
GCM\Client::configure("YOUR GOOGLE API KEY", 'MyQueueJob');
$message = GCM\Message::fromArray(array(
'registration_ids' => array('device_registration_id1', 'device_registration_id2'),
'data' => array('data1' => 123, 'data2' => 'string'),
));
/* This can all be set in the original fromArray call. */
$message
->setCollapseKey('collapse_key')
->setDelayWhileIdle(true)
->setTimeToLive(123)
->setRestrictedPackageName("com.example.trololo")
->setDryRun(true);
/* Enqueues the message. php-resque will process via a worker. */
GCM\Client::send($message);
}
}
class MyQueueJob extends \PhpGcmQueue\DefaultSendJob {
/* See DefaultSendJob for all the possible statuses */
public function tearDown() {
if($this->response) {
$failed = $this->response->getFailedIds();
if(!empty($failed['InvalidRegistration'])) {
foreach($failed['InvalidRegistration'] as $f) {
//remove from DB records
}
}
if(!empty($failed['NotRegistered'])) {
foreach($failed['NotRegistered'] as $f) {
//remove from DB records
}
}
$newIds = $this->response->getNewRegistrationIds();
if(!empty($newIds)) {
foreach($newIds as $n) {
//Update DB records
}
}
}
}
}