lkorth / php-gcm Goto Github PK
View Code? Open in Web Editor NEWAn easy to use gcm library for PHP
License: Apache License 2.0
An easy to use gcm library for PHP
License: Apache License 2.0
Google has introduced Firebase Cloud Messaging (FCM) as a replacement of GCM and started to strongly encourage to upgrade:
Is GCM going to be deprecated?
We will continue to support the current version of GCM Android and iOS SDKs because we know a lot of developers are using GCM SDKs today to handle notifications, and client app upgrade takes time.
But all new client-side features will be added to FCM SDKs only moving forward. You are strongly encouraged to upgrade to FCM SDKs.
Do you think Firebase Cloud Messaging will be supported by your library or as a new php-fcm project?
GCM has a hard limit of 1000 device ids per request to their server. Just wondering if your library has taken care of this details? Or do we need to array_chunk
ourselves?
Cheers
Ken
Hi thanks a lot for this but I'm hoping I can ask a newbie question:
I know I have to create the files in my server's folder. But how would I implement sending, would I incorporate the "Usage" section of the readme in my regular php file? If so what are the $collapsekey and $payloaddata supposed to be? I'm assuming payloaddata is the actual message, but not sure what collapsekey would be.
I send notification to multiple users via the sendMulti()-function. Then I get the response and process through the results with the getResults()-method.
But if a registration id is no longer registered (error NotRegistered), how can I figure out which registration id is no longer registered?
I have implement the gcm to send notification to my application and its really working perfect.
I am getting notification on device but issue is that I am getting logs detail may be in notification message instead of only human readable message that I am pushing.
Here is my code that I am using to send notification:
$gcmApiKey = GOOGLE_API_KEY;
$pushApi = new PushAPI();
$sender = new \PHP_GCM\Sender($gcmApiKey);
$message = new \PHP_GCM\Message("1", $messsageVal);
try {
$multicastResult = $sender->sendMulti($message, $deviceRegistrationId, 2);
$results = $multicastResult->getResults();
for ($i = 0; $i < count($deviceRegistrationId); $i++) {
$regId = $deviceRegistrationId[$i];
$result = $results[$i];
$messageId = $result->getMessageId();
if ($messageId != null) {
$canonicalRegId = $result->getCanonicalRegistrationId();
if ($canonicalRegId != null) {
// same device has more than on registration id: update it
}
} else {
$error = $result->getErrorCodeName();
if ($error == \PHP_GCM\Constants::$ERROR_NOT_REGISTERED) {
$pushApi->clearDeviceByDeviceId($regId);
}
}
}
} catch (\InvalidArgumentException $e) {
// $deviceRegistrationId was null
} catch (PHP_GCM\InvalidRequestException $e) {
// server returned HTTP code other than 200 or 503
} catch (\Exception $e) {
// message could not be sent
}
Any help will be appreciated.
Thanks in Advance.
PHP_GCM was working fine for a couple of weeks. During this time we collected more than 6000 subscribers on our website. Then suddenly Chrome users were getting the same old message again and again. Sending new messages caused the delivery of the same old message. Android users are not affected, only Chrome Web users.
We tried to contact Firebase support but they are not willing to support a third-party library or to provide any debugging support.
We are sending notifications without payload which is much quicker than the encryption needed for each single message. We also tried it with encrypted payloads but our production process dies after sending about 1300 messages. So far we could not find the root cause of this issue. However, in this case Firebase was sending the correct messages to our Chrome users.
In my opinion this is a clear bug in Firebase because the payload we send does not contain a two week old message. Does anyone else have similar issues?
Thanks,
Christoph
I'm trying out your php port of Google GCM, i copy pasted the files in the src directory to my servers directory where all my other php files are housed. I've added the line:
"require": {
"php-gcm/php-gcm": "1.1.0"
}
in the composer.json file you already had created. I am stuck in the step that says run composer.json
How do I run it when its housed in my server? I've tried opening it in the browser but that just gives me the date within it.
Hi,
https://github.com/lkorth/php-gcm/blob/master/src/PHP_GCM/Sender.php#L105
should be:
if ($attempt >= $this->retries) {
https://github.com/lkorth/php-gcm/blob/master/src/PHP_GCM/Sender.php#L110
should be:
$tryAgain = count($unsentRegistrationIds) > 0 && $attempt <= $this->retries;
thanks
Hello, as you know Google Chrome Push Notifications use GCM. But there is a downside:
A downside to the current implementation of the Push API in Chrome is that you can’t send any data with a push message. Nope, nothing. The reason for this is that in a future implementation, payload data will have to be encrypted on your server before it’s sent to a push messaging endpoint. This way the endpoint, whatever push provider it is, will not be able to easily view the content of the push message. This also protects against other vulnerabilities like poor validation of HTTPS certificates and man-in-the-middle attacks between your server and the push provider. However, this encryption isn’t supported yet, so in the meantime you’ll need to perform a fetch to get information needed to populate a notification.
In those months Google has implemented a solution that will be available in the new version Chrome 50 at the end of April 2016.
Do you think this kind of encrypted payload can be implemented into your library?
Hi
I used the library in local.
When I send a message, I receive the error : "Received error code 0 from GCM Service".
But when in the code I put the option CURLOPT_SSL_VERIFYPEER to false in Sender.php it works.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Why ?
Thank you !
Hi,
It is not a issue, just a question.
I need to run this package on a PHP 5.3.10 installation. Then, before doing anything, could anyone tell me why this package requires PHP 5.3.29?
how to set notification
payload?
Why does the namespace have an underscore instead of being 'PhpGcm' or 'Php/Gcm'?
File src/Constants.php Line number: 28
This https://android.googleapis.com/gcm/send
url getting 302. I think url should be https://gcm-http.googleapis.com/gcm/send
like this
Hey there,
when I use require lkorth "php-gcm/php-gcm": "^1.1.1" I always get an old version from 2013 with no support for multi-device push messages. Is the package name correct?
Thanks,
Henning
Why i can send multidimensional array in sendNoRetryMulti and I can't in sendNoRetry? I think you can change the code to send json enconded arrays in sendNoRetry too. If you doesn't have time, maybe, i can do i pull request to you.
Thank you.
Hi,
your example usage doesn't work anymore.
Please can you update your docs?
Another question: How can I get the registration IDs which reproduce an InvalidRegistration error to remove these IDs of my database. It worked well in a former version.
Best regards
Tobias
https://github.com/lkorth/php-gcm/blob/master/src/PHP_GCM/Sender.php#L187
should be $this->sendNoRetryMulti.
Such as
$sender = new("YOUR GOOGLE API KEY", false, "/path/to/cacert.crt");
I'm using the PHP CI framework should be sure to use the composer?
Is there any way to run without using the composer?
If you have more detailed usage it seems to be good.
$ Sender = new Sender ($ gcmApiKey);
$ Message = new Message ($ collapseKey, $ payloadData);
try {
$ Result = $ sender-> send ($ message, $ deviceRegistrationId, $ numberOfRetryAttempts);
} Catch (\ InvalidArgumentException $ e) {
// $ DeviceRegistrationId was null
} Catch (PHP_GCM \ InvalidRequestException $ e) {
// Server returned HTTP code other than 200 or 503
} Catch (\ Exception $ e) {
// Message could not be sent
}
What methods can be used to add a phrase in getBodyLocKey?
Hi! First of all, thanks for the great package.
I would like to know if you are planning to support registering and sending messages to GCM Group.
As you can see here: https://developers.google.com/cloud-messaging/notifications to support Group messages we need to be able to:
As GCM is now deprecated and will be disabled on April 2019, will we have a new release 1.1.2
with FCM support?
I see that we already have an updated URL to FCM in master
branch.
There have been a lot of changes to this repo since the last composer release. Could maintainers drop a release by chance? @lkorth
I do see the "master" note in README, but would be good to actually bump this. Latest release is over a year old
The following code:
<?php
$message = new \PHP_GCM\Message();
$message->addData('test', ['xxx' => 'yyy']);
$client = new \PHP_GCM\Sender($this->apiKey);
$client->send($message, $token, $this->retryTimes);
generates an error: Expecting string but array id found.
The other function:
<?php
$message = new \PHP_GCM\Message();
$message->addData('test', ['xxx' => 'yyy']);
$client = new \PHP_GCM\Sender($this->apiKey);
$client->sendMulti($message, $token, $this->retryTimes);
works with no exceptions, but the JSON object comes as a string:
{
"test": "{\"xxx\":\"yyy\"}"
}
Hello
There is many class for send gcm push but is different
I searched in google and knew that if device no receive push,maybe json data is invalid
do you have idea for this problem?
Hey friend I think the server code is working with the http for new ccs XMPP is used have you any PHP library for that?
Apparently we both embarked on the same mission to port the GCM code at around the same time.
Instead of doing a loosly port I did a full port including the unittests.
Would you be interested to see if we can merge the two efforts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.