每秒如何运行功能不使用任务计划程序laravel

问题描述 投票:0回答:1

我想每秒运行我的功能并广播通知,广播价格

我无法使用任务计划程序,因为我想使用用户ID和用户会话,但是任务计划程序是CLI,不能使用它

我需要一个始终可以执行代码以及访问用户和会话信息的地方。

(我的函数是无限循环)

示例代码:

while (true) {
    //last price change by curl
        $lastPrice = 23;
        $redis = Redis::connection();
        $redis->publish('lprice', $lastPrice);

         $userAvg = session('avg')[0];
        if ($lastPrice == $userAvg) {
            $notification = true;
            $redis = Redis::connection();
            $redis->publish('notification', $notification);
        }
    }
    sleep(5);
}
laravel events real-time broadcast
1个回答
0
投票
为此使用cron作业。它会在给定时间后运行,这是一个连续的过程。但是最佳实践是任务调度,因为您正在使用laravel框架。
© www.soinside.com 2019 - 2024. All rights reserved.