web-push-php-example | sending Web Push notifications , using web | Notification library
kandi X-RAY | web-push-php-example Summary
kandi X-RAY | web-push-php-example Summary
An example for sending Web Push notifications, using web-push-php
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Subscribe to the user
- Unsubscribe from the server
- Change the current push button state
- Checks the notification for notification permissions .
- Updates the subscription to the server
- Send a subscription to the server .
- Convert a UInt8Array to a Uint8Array .
web-push-php-example Key Features
web-push-php-example Examples and Code Snippets
Community Discussions
Trending Discussions on web-push-php-example
QUESTION
I an creating a PWA app and its working fine, but when I tried to upload on server I stuck on error. On windows local server, everything is fine even notifications, and I dont know much putty/linux commands.
check here my phpinfo file.
I am tring to upload to amazon ec2 server. I installed apache, php, ssl and other required things. And its working file except notifications.
When I call my notification file, I got 503 response. I installed composer, installed everything. I used this github library.
As I understand, I stuck on gmp extension, When I open phpinfo() I didnt see gmp over there. I installed gmp using sudo yum install php-gmp
and also I see a file in php.d named as 20-gmp.ini and it included extension=gmp
. Also restarted apache server using sudo apachectl stop
, sudo apachectl start
.
But still I am getting error. And I coudnt see gmp in phpinfo().
notificationb.php
...ANSWER
Answered 2019-Apr-27 at 09:38I know I am commenting my own question, As I was searching this answer for 3-4 days I think I should share this info with everyone.
The issue is, In linux, PHP have different-different configuration files. The main configuration file is php.ini. And it include other extensions after loading this file and override mail file. These additional configuration are located in /etc/php.d/
(in my case, which is common for mostly).
So just restarting apache server in not enough. We need to also restart php-fpm.
To restart php-fpm: sudo service php-fpm restart
And then restart apache: sudo apachectn restart
You can check more here
QUESTION
I am building a web push notification system and I am using the concept used in this example:
https://github.com/Minishlink/web-push-php-example
I have the following code in my JS file. It checks for API support, checks if notifications are not disabled, registers the service worker, asks for permission to display notifications, if allowed subscribes the user and sends the details to the server. If the user is already subscribed, it updates the endpoint value in the DB.
When I run this on Firefox 61, it works fine, but when I run it on Chrome 67 I get this error:
...ANSWER
Answered 2018-Jul-13 at 09:08 if(subscription){
const key = subscription.getKey('p256dh');
const token = subscription.getKey('auth');
const contentEncoding = (PushManager.supportedContentEncodings || ['aesgcm'])[0];
return fetch('/scripts/notification-subscribe.php', {
method: 'POST',
body: JSON.stringify({
endpoint: subscription.endpoint,
publicKey: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : null,
authToken: token ? btoa(String.fromCharCode.apply(null, new Uint8Array(token))) : null,
contentEncoding,
user: 1,
}),
}).then(() => subscription);
}
}
Just modify this function hope pushSubscription with if block it works
QUESTION
I used the web push library to send push notifications https://github.com/web-push-libs/web-push-php
I getting an internal error while trying to sen push notification
I checked in both PHP version:7.1.22,7.2.9-1
Apache error log throws :
[:error][client ::1:33302] PHP Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /PWA/web-push-php-example/vendor/minishlink/web-push/src/Subscription.php on line 41, referer: http://localhost/PWA/web-push-php-example/src/
And i also tried in Ngnix / error log :
17:22:36 [error] 20232#20232: *46 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined index: endpoint in /var/www/html/PWA/web-push-php-example/vendor/minishlink/web-push/src/Subscription.php on line 69 PHP message: PHP Fatal error: Uncaught TypeError: Argument 1 passed to Minishlink\WebPush\Subscription::__construct() must be of the type string, null given, called in /var/www/html/PWA/web-push-php-example/vendor/minishlink/web-push/src/Subscription.php on line 72 and defined in /var/www/html/PWA/web-push-php-example/vendor/minishlink/web-push/src/Subscription.php:39 Stack trace: thrown in /var/www/html/PWA/web-push-php-example/vendor/minishlink/web-push/src/Subscription.php on line 39" while reading response header from upstream, client: 127.0.0.1, server: local.pwa.com, request: "POST /PWA/web-push-php-example/src/send_push_notification.php HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "localhost", referrer: "https://localhost/PWA/web-push-php-example/src/"
PHP code :
...ANSWER
Answered 2018-Sep-21 at 11:13Are you absolutely sure you are actually running PHP 7.21 or 7.2? The problem is the question marks in the constructor here:
https://github.com/web-push-libs/web-push-php/blob/master/src/Subscription.php#L41-L43
As you can see from this 3v4l code, it works on all versions over 7.1:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install web-push-php-example
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page