[英]How to send Web push notifications automatically when database event occurs? Angular + PHP + MySQL
I'm developing a gym website using Angular 6 with service workers that needs to send notifications to users (Web push notifications) when the class they are subscribed to is going to begin (for example 15 minutes before the start time).我正在开发一个使用 Angular 6 的健身房网站,其中包含需要在用户订阅的课程开始时(例如在开始时间前 15 分钟)向用户发送通知(Web 推送通知)的服务工作者。
By the time I have a PHP function that uses Minishlink\\WebPush to send the notification, so I need to call that function 15 minutes before the class starts, and it has to be done automatically because there's no interaction of the user in order to call that function.当我有一个使用 Minishlink\\WebPush 发送通知的 PHP 函数时,所以我需要在课程开始前 15 分钟调用该函数,并且必须自动完成,因为没有用户交互才能调用那个功能。
I've thought about having a MySQL event that consults the table where classes are stored, and when the time has arrived calls that PHP function but I don't know how to do it, and even if it is the best idea.我想过有一个 MySQL 事件来查询存储类的表,当时间到了时调用该 PHP 函数,但我不知道如何去做,即使这是最好的主意。
Any suggestions?有什么建议?
I'm using Angular 6 + PHP + MySQL running locally on XAMPP.我正在使用在 XAMPP 上本地运行的 Angular 6 + PHP + MySQL。
the best way to this and handle such situation is to create a cron and dynamic cron timing to execute Minishlink\\WebPush send function.处理这种情况的最好方法是创建一个 cron 和动态 cron 定时来执行 Minishlink\\WebPush 发送功能。
we have also handled such situation using cron, but the use case was different.我们也使用 cron 处理过这种情况,但用例不同。 our cron runs every 15 mins checks the if data is there in mongo DB if it is there send a push notification to that user.我们的 cron 每 15 分钟运行一次,检查 mongo DB 中是否存在数据(如果存在)向该用户发送推送通知。
in your case, you can create a specific cron task as soon as user scheduled his timings more helpful information is here on this answer.在您的情况下,您可以在用户安排他的时间安排后立即创建特定的 cron 任务,此答案中提供了更多有用的信息。
I hope this will help you.我希望这能帮到您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.