php - 每微秒发送一次推送通知
问题描述
我有 MySQL 数据库,它每秒或微秒更新一次。使用通知表我必须找到正确的用户来发送推送通知,通知有几种类型。因此,并非所有通知都发送给所有用户,而是我必须检查哪个用户订阅了哪个通知,并据此向用户发送通知,到目前为止它工作正常但不准确。
我的程序逻辑是:
首先从待发送的通知表中获取所有新通知。
$newnotification = get_all_newnotification();
然后处理通知以检查是否有任何用户订阅此通知?如果是,则使用 Firebase 发送以推送给该用户
foreach ($newnotification as $data) {
$findusers = mysqli($connection,"SELECT U.device_token FROM user_notification as UN INNER JOIN user as U on U.id = UN.user_id WHERE UN.notification_type = '{$data['type']}' ");
$user_token = [];
while($result = mysqli_fetch_assoc()) {
$user_token[] = $result['device_token'];
}
if(count($user_token) > 0) {
$firebase = new Firebase();
$notification_data['title'] = 'Title here';
$notification_data['description'] = 'Description goes here';
$firebase->send($user_token,$notification_data);
}
//here I'm updating notification sent flag in table so won't get next time
}
所以这个工作但不是按要求的,因为当上述程序完成时,表中插入了许多新通知,然后用户将收到 5 到 10 分钟的通知延迟(取决于上述程序执行时间)
有谁知道如何尽快发送通知?
解决方案
推荐阅读
- c++ - 数组嵌套结构初始化
- c# - 反序列化 JSON 并返回 C# 中的值?
- awk - gawk:为 1 个或多个多字段文件模拟 uniq -cd,合并重复的详细信息并使用计数和路径格式化输出
- javascript - 为什么重复功能第二次不起作用?
- android - Could not able to connect Bluetooth in android
- glib - Remove a GSource(timeout) and adding the same GSource to the same context without recreating the source
- python - int() argument must be a string, a bytes-like object or a number, not 'NoneType' Django
- java - Java/Firestore - Wait for data to be read before looping to next item (Async)
- r - How to connect geom_line to forecast fan using the fable package
- redis - Redis Secondary Indexes and Performance Question