3

我想使用 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);
4

1 回答 1

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);
    }
} 
于 2013-06-07T09:07:03.597 回答