PHP ob_flush flush()不起作用

时间:2017-02-01 17:21:16

标签: php flush

在说什么之前。我已经找到了解决方案。我现在试图解决这个问题。

我目前正在尝试通过每次下载文件时回显来显示ftp下载的进度。

这是我的代码的一部分:

<?php

header('Content-type: text/html; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate');
header('X-Accel-Buffering: no');

// ftp connection stuff goes here

$string_length = 4096;

for ($i=0; $i < $filesLength; $i++) {

    if (ftp_get($ftp_conn, './downloads/'.$files[$i]['local'], $files[$i]['server'], FTP_ASCII)) {
        echo 'File: '.$files[$i]['local'].' saved.<br>';

        // $string = str_repeat('.', $string_length);
        // echo '<div style="display:none;">'.$string . '</div>';

        ob_flush();
        flush();
    } else {
        echo "Error";
    }

}

Theres 2评论说,如果我取消注释它的一切工作。

我该怎么做才能使这项工作?

1 个答案:

答案 0 :(得分:0)

我猜我没有找到合适的解决方案。

我最终使用4kb字符串来触发冲洗。

这有效,但不是预期的。

相关问题