对Heroku进行异步Artisan::调用



我有一个用流明编写并部署在heroku上的HTTP端点,该端点正在调用Artisan::call("queue:work"…(来开始处理一些队列作业。

public function startProcess(Request $request)
{

Artisan::call('queue:work', ['--stop-when-empty', '--max-jobs' => 1]);
return 'ok';

}

由于heroku允许30秒的最大超时,进程失败了,因为Artisan::调用是同步的,有什么方法可以使它异步吗?

如果您想要,您可以在返回响应后继续处理

public function startProcess(Request $request)
{
// dont abort script execution if client disconnect
ignore_user_abort(true);
// dont limit the time
set_time_limit(0);
// turn on output buffering
ob_start();
// prepare the response
// send the response
return 'ok';
header('Connection: close');
header('Content-Length: '.ob_get_length());
// turn off output buffering
ob_end_flush();
// flush system output buffer
flush();
// continue processing
Artisan::call('queue:work', ['--stop-when-empty', '--max-jobs' => 1]);
}

最新更新