webman 让用户下载动态生成的数据 限制速度

shixia

我在tp6中是已经有了解决方案的,但是在webman中这个方法并不适用
以下是TP6中的代码

private function down($data)
    {
        header("Cache-Control: max-age=0");
        header("Content-Description: File Transfer");
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="' . date('Y-m-d h:i:s', time()) . '.txt"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Pragma: public');
        header('Cache-Control: must-revalidate');
        ob_flush();
        flush(); // 刷新内容
        $arr = str_split($data, 204800);
        $num = count($arr);
        for ($i = 0; $i < $num; $i++) {
            print $arr[$i];
            ob_flush();
            flush();
            sleep(1);
        }
        return response('');
    }

但是由于在webman中 任何打印输出函数都会输出到控制台暂时没想到解决方案 想加群也没有反应

1001 1 0
1个回答

walkor

webman不支持限速。打印输出用ob_start()ob_get_clean() 来获取。

$arr = str_split($data, 204800);
$num = count($arr);
ob_start();
for ($i = 0; $i < $num; $i++) {
    print $arr[$i];
}
$content = ob_get_clean();
return response($content);
  • 暂无评论
年代过于久远,无法发表回答
🔝