2013-10-28 65 views
0

我正在使用以下代码通过下载链接控制带宽使用情况。下面是我与实施QOS Bandwidth Throttle PHPQoS带宽限制不起作用

// 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() :(

谁能告诉我的工作,有什么错了,我在这里做

+0

嗯,到底发生了什么? –

+0

@Pekka웃对不起,我忘了提到确切的问题,我已经更新了问题底部的问题。 –

+0

Lo确定在文件中。它包含什么? –

回答

0

试试这个:

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

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

+0

我试过了,用这个下载工作,但冻结了所有其他的进程。就像:点击下载链接后,我将页面重定向到其他地方,现在它的重定向在下载完成后,而不是点击事件后:( –