【问题标题】:Heroku PHP continue process execution after sending a responseHeroku PHP 在发送响应后继续进程执行
【发布时间】:2022-10-08 17:15:00
【问题描述】:

我有一个代码在返回对请求的 ok 200 响应后运行轻型后台任务。

该代码在大多数 apache 服务器上运行良好,它在 heroku 上运行但最近停止,现在在整个代码运行后返回响应。

有什么解决办法???

ob_start();
ignore_user_abort(); // optional

echo ('{"text": "json Response message to the user".}'); // JSON Response
header('Content-Length: ' . ob_get_length());
header('Content-Type: '.'application/json');
header("Connection: close");

ob_end_flush();
ob_flush();
flush();    
session_write_close(); // Added a line suggested in the comment


// Background task here
sleep(1);
echo('Response the user will never see');

for ($i=0; $i<12; $i++) {
    sleep(1);
}

【问题讨论】:

    标签: php laravel multithreading heroku lumen


    【解决方案1】:

    在脚本的最后一行添加exit();

    【讨论】:

      猜你喜欢
      • 2011-04-19
      • 1970-01-01
      • 2018-09-19
      • 2018-03-24
      • 2021-02-20
      • 2012-09-01
      相关资源
      最近更新 更多