QoS带宽限制无法正常工作

时间:2013-10-28 12:29:55

标签: php

我使用以下代码通过下载链接控制带宽使用情况。以下是我在使用QOS Bandwidth Throttle PHP

的实现时使用的代码
// create new config
$config = new ThrottleConfig();
// enable burst rate for 30 seconds
$config->burstTimeout = 30;
// set burst transfer rate to 50000 bytes/second
$config->burstLimit = 10000;
// set standard transfer rate to 15.000 bytes/second (after initial 30 seconds of burst rate)
$config->rateLimit = 15000;
// enable module (this is a default value)
$config->enabled = true;

// start throttling
$x = new Throttle($config);


header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"".$zipname."\"");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$zipname."\"");
header("Content-Length: ".filesize($directory_location . '/' . $zipname));

我收到损坏的文件,没有实际大小(4MB),我得到大约(2KB)大小。如果我使用readfile()函数,那么我没有找到使用readfile()的油门类:(

有谁能告诉我,我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

试试这个:

$x = new Throttle($config);
$handle = fopen("yourfile.zip", "rb");
while (!feof($handle)) {
  echo fread($handle, 8192);
  flush();
}
fclose($handle);

您也可以尝试ob_flush()而不是flush()。