How to send push / php notifications with closed site window?

7

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

Searching the internet, I could not find a way to do this in conjunction with PHP. So I'm calling for stackoverflow.

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

    
asked by anonymous 29.09.2016 / 13:46

1 answer

4

To implement this feature use the Html5 Push API. Watch out for compatibility with browsers.

Another caution you must have is that PHP is not a good language for implementing daemons, that is, implementing websockets is a shot in the foot. PHP is designed for processes to start and end, keeping a process running will greatly increase the memory and processing usage of your server. Since PHP has no way to manage memory, you only have to rely on the garbage collector, which is a bad idea. (If you have any questions about this, here's an explanation link )

Although the Push API does not use websockets, keep this in mind, it is better to use another language if you want a real-time notification system. And also think about the situation that by working with workers, you will receive calls in short times from all users that enable this feature, which can weigh on your server due to the high number of processes that will be opened depending on 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 / if 6000 / m adds this to the average number of visits on your site per minute and will have the total of executed processes. It will come to the conclusion that it is not a good thing to leave this type of resource in PHP's hand, since the processing used is very high.

So you will find few examples in PHP about features such as notifications.

Some PHP implementations

References:

10.11.2016 / 06:32