dscojuxf69080 2019-01-29 05:13
浏览 34

在php不确定时,connection_aborted阻止执行吗?

I need to precisely monitor the amount of data downloaded, this is my test function:

function reply_file($path) {
    reply_file_headers($path);
    $size = 0;
    $in = fopen($path, "r");
    $out = fopen("php://output", "w");
    while (!feof($in) && !connection_aborted()) {
        $buffer = fread($in, 16 * 1024);
        fwrite($out, $buffer);
        $size += strlen($buffer);
    }
    fclose($out);
    fclose($in);
    return $size;
}

I tested it in 3 scenarios:

  1. I let the download complete
  2. I cancel the download client
  3. I physically disable the connection

The first 2 scenarios work as expected and the size returned is correct as to what was received on the other side.

The third scenario has me a bit puzzled, it does return the correct size... eventually, it takes around a minute for it to get to the end of the function, even if it exceeds the script time limit.

If I remove connection_aborted it just goes on to the end as apparently it has no problem writing to the output stream even if there is nobody on the other side.

Now its great that its still working but there is no mention of the blocking feature in PHP documentation. Is this standard behavior or whats happening here exactly?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题