How do I send push/php notifications with the site window closed?

Asked

Viewed 5,161 times

7

From time to time (I think 2014 onwards), facebook has been making browser notifications using the HTML5 Notifications API. The curious thing is that facebook can send notifications, even though your page is closed.

Searching the internet, I couldn’t find a way to do this in conjunction with PHP. That’s why I’m appealing to stackoverflow .

I know that there are solutions like Pushlead, and Pushcrew. But they are of no use if I want to use my own system. Using only an example of frontend, the script itself is useless, without a language that acts on the server to send news to users of the site. On similar topics already created, nothing serves my specific question: How to send push/php notifications with closed site window?

  • How do you want to receive notifications if your browser is closed? In that case, notifications would be viewed where?

1 answer

4


To implement this feature use the Html5 Push API. Stay tuned for browser compatibility.

Another caution you should take is that PHP is not a good language to implement daemons, that is, implement websockets is a shot in the foot. PHP was made so that the processes start and have an end, keeping a process always active will greatly increase the use of memory and processing of your server. Since PHP has no way to manage memory you will only have to rely on Garbage Collector, which is a bad idea. (If you have any questions about this, here is an explanation https://software-gunslinger.tumblr.com/post/47131406821/php-is-meant-to-die)

Although Push API does not use websockets, keep this in mind, it is best to use another language if you want a real-time notification system. And also think of the situation that by working with Workers, you will receive short-time calls from all users who enable this feature, what may weigh on your server due to the high number of processes that will be opened as the number of users of your site/system increases.

For example:

If your system has 100 users and notifications are checked every 5 seconds, the minimum request you will have is 100/s and 6000/m add that to the average number of visits to your site per minute and you will have the total of processes executed. You will come to the conclusion that it is not a good thing to leave this type of feature in the hand of PHP, because the processing used is very high.

That’s why you’ll find few examples in PHP about features like notifications.

Some PHP implementations

References:

  • My goal was to create a new notification system for vloggers. So I think a system that sends one notification a day would be enough. I recently discovered that I could do this in AJAX (still consuming server resources). Your help contributes a lot of friend. I still accept suggestions.

  • This post left me with a question, will you join PHP + Cron Linux to push the messages instead of leaving it only with PHP?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.