0

我正在使用以下代码通过下载链接控制带宽使用。这是我在实现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():(

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

4

1 回答 1

0

尝试这个:

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

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

于 2013-10-28T13:18:51.930 回答