drgawfsf1069 2018-09-15 09:36
浏览 65

每微秒发送推送通知

I have MySQL database which is updating every second or microsecond. using notification table I have to find a correct user to send a push notification, there are several types of the notification. so not all notification send to all user's instead I have to check which user subscribe to which notification and based on that I'm sending a notification to users, so far it's working correctly but not accurate.

My program logic is:

First getting all new notification from notification table which is pending to send.

$newnotification  = get_all_newnotification();

Then processing notification to check is there any user subscribe to this notification? if yes then sending to push to that user using 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
}

So this working but not as required, because while above program finished there are many new notifications inserted in the table, then user will receive notification delay of 5 to 10 minutes (depends on above program execution time)

Does anyone know how to send notification as soon as possible?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算