Reputation: 6597
I need to show a push notification once a week, even when the user is not on the page. I know it is possible to use service workers to push a notification based on a "feed", but I don't know if it is possible to push a notification at a specific date.
If it is possible, how could it be done with PHP (, if needed, and JavaScript, of course)?
Upvotes: 0
Views: 129
Reputation: 56064
Assuming you're okay with using Firebase, one approach is to follow the general advice that came up in another question, and customize it for the web:
Use Firebase Cloud Messaging's JavaScript SDK to implement your service worker's push message handler in your web clients.
"Fake" a cron job by POST
ing to a Firebase cloud function, following the example in this sample app. If you already have a PHP server running, that could be used to periodically trigger the Firebase cloud function. Alternatively, you could skip the Firebase cloud functions part entirely, and use your PHP server to trigger the push message directly.
Upvotes: 1