【问题标题】:Make an asynchronous Artisan::call on Heroku在 Heroku 上进行异步 Artisan::call
【发布时间】:2021-05-11 19:47:52
【问题描述】:

我有一个用 lumen 编写并部署在 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::call 是同步的,有什么方法可以使其异步?

【问题讨论】:

    标签: php laravel heroku lumen


    【解决方案1】:

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

        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]);
        }
    

    【讨论】:

      猜你喜欢
      • 2017-08-08
      • 2015-05-16
      • 2014-12-17
      • 2016-08-31
      • 2021-06-06
      • 1970-01-01
      • 2020-12-16
      • 2013-05-25
      • 2019-06-05
      相关资源
      最近更新 更多