Recommend this page to a friend!
  Classes of Stefan Kientzler  >  PHP Web Push Notifications Server  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Web Push Notifications Server
Queue and push notifications to Web users
Author: By
Last change: Update
Date: 3 months ago
Size: 3,822 bytes


Class file image Download

PNServer - Web Push Notifications for your Homepage

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

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.

there are no dependencies to other external libraries!

required PHP Libraries

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


You can download the Latest release version from

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  = '';
  // 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';

you can generate your own VAPID key on


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

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

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

rename to MyVapid.php and set your own keys:

  $oVapid = new PNVapid(


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.

For more information send a message to info at phpclasses dot org.