Recommend this page to a friend! |
Classes of Stefan Kientzler | PHP Web Push Notifications Server | readme.md | Download |
|
DownloadPNServer - Web Push Notifications for your HomepageWith 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
there are no dependencies to other external libraries! InstallationYou can download the Latest release version from PHPClasses.org required adaptions for your own project (in PNServiceworker.js):
There are several websites where you can generate your own VAPID key. E.g.: UsageA 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:
LoggingThis 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. |