Laravel连续运行artisan命令
我想做的是在服务器上连续运行artisan命令。我知道Laravel中有cronjobs和调度,但这不起作用,因为处理过程需要调用API,有时需要1秒,有时需要15秒。所以我想继续运行它 我已经找到了这个拼图的好几块,但还不能完全拼合起来 假设我的自定义artisan artisan命令中有以下内容:Laravel连续运行artisan命令,laravel,Laravel,我想做的是在服务器上连续运行artisan命令。我知道Laravel中有cronjobs和调度,但这不起作用,因为处理过程需要调用API,有时需要1秒,有时需要15秒。所以我想继续运行它 我已经找到了这个拼图的好几块,但还不能完全拼合起来 假设我的自定义artisan artisan命令中有以下内容: public function handle() { $this->info('Test'); } 如果我现在运行nohup php artisan customcommand我会得到
public function handle()
{
$this->info('Test');
}
如果我现在运行nohup php artisan customcommand
我会得到将输出附加到nohup.out
。文件nohup.out只有一次“Test”。因此,它似乎没有连续运行handle()
函数
现在,如果我这样做并使用nohup
运行它:
public function handle()
{
$i = 1;
while(true)
{
$this->info('Test '.$i);
sleep(5);
$i++;
}
}
它确实连续运行,我在nohup.out
中得到测试1、测试2等。使用while(true)
循环会让人感觉不舒服。这样做对吗
最终,$this->info('Test')
将被一个控制器函数替换,该函数应连续运行,但希望确保基本操作正确
更新
如果我执行以下操作,我会得到一个PHP致命错误:允许的内存大小为268435456字节(尝试分配20480字节)
因此在while循环中实例化一个新的控制器似乎不是一个好主意
public function handle()
{
while(true)
{
$controller = new MyController;
$controller->index();
}
}