php 请求 响应,发送http响应后继续处理php

0a89f97ce45bf9f36163a305a1c23edc.png

哔哔one

我在这里看到了很多建议ignore_user_abort(true);但是这个代码是不必要的。所有这一切都是确保您的脚本在用户中止时在发送响应之前继续执行(通过关闭他们的浏览器或按转义来停止请求)。但这不是你想要的。您要求在发送响应后继续执行。你所需要的只是以下几点:    // Buffer all upcoming output...

    ob_start();

    // Send your response.

    echo "Here be response";

    // Get the size of the output.

    $size = ob_get_length();

    // Disable compression (in case content length is compressed).

    header("Content-Encoding: none");

    // Set the content length of the response.

    header("Content-Length: {$size}");

    // Close the connection.

    header("Connection: close");

    // Flush all output.

    ob_end_flush();

    ob_flush();

    flush();

    // Close current session (if it exists).

    if(session_id()) session_write_close();

    // Start your background work here.

    ...如果您担心后台工作会比PHP的默认脚本执行时间长,那么坚持set_time_limit(0);在顶端。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值