使用php的网页带宽控制

时间:2013-06-07 06:38:52

标签: php webpage bandwidth

我想使用php设置网页的带宽。

我有一些PHP代码来设置下载文件的带宽,但我想为网页设置带宽。

是否可以使用php设置网页的带宽?

如果可能,请提供示例代码或工作链接以供参考。

以下代码用于发送下载文件的带宽

set_time_limit(0);
$filedownload = "files/abc.exe";
$time = 10000;
$obytes = 150*1024; //150k download speed restriction
$fd = fopen ($filedownload, "rb");
while (!feof ($fd)) {
    list($usec, $sec) = explode(" ", microtime());
    $time_start = $usec + $sec;
    $bytes = ceil($obytes/100);
    echo fread($fd, $bytes);
    flush();

    if($time < 10000) usleep(10000-$time);
    $i++;
    list($usec, $sec) = explode(" ", microtime());
    $time_end = $usec + $sec;
    $time =ceil(($time_end - $time_start)*1000000)+10;
}
fclose ($fd);

1 个答案:

答案 0 :(得分:0)

我找到了这个问题的编码

$speed = 10;

ob_start();

include(filename.php);
$now = time();
foreach(str_split(ob_get_clean(), $speed*1024) as $chunk)
{
    echo $chunk;
    flush();
    $now++;
    while($now > time())
    {
        usleep(1000000);
    }
}