可能重复:
尽早关闭连接
在PHP中响应ajax请求后如何继续处理?
我需要在ajax操作中断开连接:
$response = getResponse($params);
echo $response; // don't make user to wait
flushAndDropConnection();
someLongActionsFor5Seconds();
我该怎么做?
只需让用户断开连接,但保持脚本运行。
ignore_user_abort(true);
ob_start();
echo "response";
$size = ob_get_length();
header("Content-Length: $size");
header('Connection: close');
ob_end_flush();
ob_flush();
flush();
if (session_id()) session_write_close();
//your long running action here