PHP Classes

PHP Web Push Notifications Server: Queue and push notifications to Web users

Recommend this page to a friend!
  Info   View files Example   View files View files (54)   DownloadInstall with Composer Download .zip   Reputation   Support forum (8)   Blog (2)    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 79%Total: 1,910 This week: 8All time: 2,061 This week: 16Up
Version License PHP version Categories
pnserver 1.2.0Freely Distributable7.4Web services, PHP 7
Description 

Author

This package can queue and push notifications to Web users.

It can register the interest of users to receive notifications from the server by creating user subscriptions.

The package provides means to queue notification messages to be sent to users of an application by storing them in a database.

Then it can return queued messages, so they can be shown to Web uses on a Web page using custom JavaScript code that pulls the messages from the server using this package.

The package can also automatically delete expired messages and no longer valid subscriptions.

Recommendations

Push notifications for web browsers and now Apple iOS 16.4 pwa
I can’t find any packages that are current and work for webpush

Innovation Award
PHP Programming Innovation award winner
April 2020
Winner
Web based push notifications are useful to let users of a site know about anything new that happens on a site that may be of the interest of those users.

This package provides a complete solution to register users interested to subscribe to get notifications from a site, queue notifications to be pushed to the users when they come to the site, and even perform maintenance on the notifications and subscriptions created by the users.

Manuel Lemos
Picture of Stefan Kientzler
  Performance   Level  
Name: Stefan Kientzler <contact>
Classes: 18 packages by
Country: Germany Germany
Innovation award
Innovation award
Nominee: 11x

Winner: 6x

Details

PNServer - Web Push Notifications for your Homepage

Latest Stable Version License Donate Minimum PHP Version PHPStan Scrutinizer Code Quality codecov

With this package, web push notifications can be created, encrypted and sent via HTTP request. The subscriptions can be saved and managed. Optionally, the package automatically deletes expired or no longer valid subscriptions. The JavaScript code required on the client side is also included in the package - this has to be slightly adapted to your own project.

> Important: > > The client side of this package works with the Javascript Notification API, which is only available in a secure context (HTTPS). Thus, the complete package also depends on running in a secure context (also in the test environment - unless both the server and the client run on the *'localhost'*). > > Here you can read more about how to set up a secure context in the local development environment.

required PHP Libraries

  • cURL (curl)
  • Multibyte String (mbstring)
  • OpenSSL (openssl)
  • GNU Multiple Precision (gmp)
  • BC Math (bcmath)

there are no dependencies to other external libraries!

Installation

You can download the Latest release version from PHPClasses.org

required adaptions for your own project (in PNServiceworker.js):

  // VAPID appPublic key
  const strAppPublicKey   = 'create your own VAPID key pair and insert public key here';
  // URL to save subscription on server via Fetch API
  const strSubscriberURL  = 'https://www.your-domain.org/PNSubscriber.php';
  // default Notification Title if not pushed by server
  const strDefTitle       = 'Your company or product';
  // default Notification Icon if not pushed by server
  const strDefIcon        = './elephpant.png';

There are several websites where you can generate your own VAPID key. E.g.:

Usage

A tutorial describing the individual steps for using the package is available at PHPclasses.org.

PnTestClient.html shows a simple example Page to subscribe the push notifications.

PNTestServer.php demonstrates, how the Notification Server can be implemented:

rename MyVapid.php.org to MyVapid.php and set your own keys:

  $oVapid = new PNVapid(
      "mailto:yourmail@yourdomain.de",
      "your-generated-public-key",
      "your-generated-private-key"
  );

Logging

This package can use any PSR-3 compliant logger. The logger is initialized with a NullLogger-object by default. The logger of your choice have to be passed to the constructor of the PNDataProvider and set via setLogger() method to the PNServer.

If you are not working with a PSR-3 compatible logger so far, this is a good opportunity to deal with this recommendation and may work with it in the future.

There are several more or less extensive PSR-3 packages available on the Internet.

You can also take a look at the 'XLogger' package and the associated blog 'PSR-3 logging in a PHP application' as an introduction to this topic.

  Files folder image Files  
File Role Description
Files folder imagePsr (1 directory)
Files folder imageSKien (2 directories)
Accessible without login Plain text file autoloader.php Aux. Auxiliary script
Accessible without login Image file elephpant.png Icon Icon image
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file MyLogger.php Example Example script
Accessible without login Plain text file MyVapid.php.org Example Example script
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml.org Data Auxiliary data
Accessible without login Plain text file PNClient.js Data Auxiliary data
Accessible without login Plain text file PNSendWelcome.php Example Example script
Accessible without login Plain text file PNServiceWorker.js Data Auxiliary data
Accessible without login Plain text file PNSubscriber.php Example Example script
Accessible without login Plain text file PNTestClient.html Data Example HTML page client
Accessible without login Plain text file PNTestPushSingle.php Example Example script
Accessible without login Plain text file PNTestServer.php Example Example script
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files  /  Psr  
File Role Description
Files folder imageLog (8 files)

  Files folder image Files  /  Psr  /  Log  
File Role Description
  Plain text file AbstractLogger.php Class Class source
  Plain text file InvalidArgumentException.php Class Class source
  Plain text file LoggerAwareInterface.php Class Class source
  Plain text file LoggerAwareTrait.php Class Class source
  Plain text file LoggerInterface.php Class Class source
  Plain text file LoggerTrait.php Class Class source
  Plain text file LogLevel.php Class Class source
  Plain text file NullLogger.php Class Class source

  Files folder image Files  /  SKien  
File Role Description
Files folder imagePNServer (9 files, 1 directory)
Files folder imageTest (1 directory)

  Files folder image Files  /  SKien  /  PNServer  
File Role Description
Files folder imageUtils (4 files)
  Plain text file PNDataProvider.php Class Class source
  Plain text file PNDataProviderMySQL.php Class Class source
  Plain text file PNDataProviderSQLite.php Class Class source
  Plain text file PNEncryption.php Class Class source
  Plain text file PNPayload.php Class Class source
  Plain text file PNServer.php Class Class source
  Plain text file PNServerHelper.php Class Class source
  Plain text file PNSubscription.php Class Class source
  Plain text file PNVapid.php Class Class source

  Files folder image Files  /  SKien  /  PNServer  /  Utils  
File Role Description
  Plain text file Curve.php Class Class source
  Plain text file Math.php Class Class source
  Plain text file NistCurve.php Class Class source
  Plain text file Point.php Class Class source

  Files folder image Files  /  SKien  /  Test  
File Role Description
Files folder imagePNServer (12 files, 1 directory)

  Files folder image Files  /  SKien  /  Test  /  PNServer  
File Role Description
Files folder imagetestdata (6 files)
  Plain text file PNDataProviderMySQLTest.php Class Class source
  Plain text file PNDataProviderSQLiteTest.php Class Class source
  Plain text file PNDataProviderTest.php Class Class source
  Plain text file PNEncryptionTest.php Class Class source
  Plain text file PNPayloadTest.php Class Class source
  Plain text file PNServerTest.php Class Class source
  Plain text file PNSubscriptionTest.php Class Class source
  Plain text file PNVapidTest.php Class Class source
  Plain text file TestHelperTrait.php Class Class source
  Plain text file UtilsCurveTest.php Class Class source
  Plain text file UtilsMathTest.php Class Class source
  Plain text file UtilsPointTest.php Class Class source

  Files folder image Files  /  SKien  /  Test  /  PNServer  /  testdata  
File Role Description
  Accessible without login Plain text file expired_subscription.json Data Auxiliary data
  Accessible without login Plain text file gone_subscription.json Data Auxiliary data
  Accessible without login Plain text file invalid_subscription.json Data Auxiliary data
  Accessible without login Plain text file inv_endpoint_subscription.json Data Auxiliary data
  Accessible without login Plain text file notfound_subscription.json Data Auxiliary data
  Accessible without login Plain text file valid_subscription.json Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:1,910
This week:8
All time:2,061
This week:16Up
User Ratings User Comments (1)
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:96%StarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:79%StarStarStarStar
Rank:30