每微秒发送推送通知

tktrz96b  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(277)

我有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分钟的通知延迟(取决于上述程序的执行时间)
有人知道如何尽快发送通知吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题