有时候需要限制一下用户下载文件的速度,可以
(公司有个需求,防止人不停地下载,在别人的网站里看到的)以下翻译来自Google这个类可以用来限制下载文件的速度。它拦截PHP脚本的输出提供给浏览器设置一个缓冲处理,被称为每
(公司有个需求,防止人不停地下载,在别人的网站里看到的)
以下翻译来自Google
这个类可以用来限制下载文件的速度。
它拦截PHP脚本的输出提供给浏览器设置一个缓冲处理,被称为每次定的字节数。
类自最后一次测量的时间PHP输出缓冲液冲洗,并保持一段时间,如果对PHP的平均下载速度超过给定的限制。
-------------------------------------------------- -------------------------
有三种不同的带宽整形机制,以确保有足够的服务质量:
1 )突发性传输速率将关闭X字节后发送给用户(这可以帮助的很快送小图像,并限制下载速度,巨大的文件)
2 )突发性传输速率将关闭一段时间,以秒后,它将恢复到标准节流速度
3 )突发传输速率不会被激活,下载速度的限制将是恒定的(在这种情况下,在整个下载过程$配置> burstLimit必须等于配置 - > rateLimit )
以下翻译来自Google
这个类可以用来限制下载文件的速度。
它拦截PHP脚本的输出提供给浏览器设置一个缓冲处理,被称为每次定的字节数。
类自最后一次测量的时间PHP输出缓冲液冲洗,并保持一段时间,如果对PHP的平均下载速度超过给定的限制。
-------------------------------------------------- -------------------------
有三种不同的带宽整形机制,以确保有足够的服务质量:
1 )突发性传输速率将关闭X字节后发送给用户(这可以帮助的很快送小图像,并限制下载速度,巨大的文件)
2 )突发性传输速率将关闭一段时间,以秒后,它将恢复到标准节流速度
3 )突发传输速率不会被激活,下载速度的限制将是恒定的(在这种情况下,在整个下载过程$配置> burstLimit必须等于配置 - > rateLimit )
<?php
//throttler类太长可以到:http://www.codepearl.com/files/160.html下载
require("./throttler.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 = 50000;
// 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);
//http://www.codepearl.com
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"test.txt\"");
header("Content-Length: 60000000");
// generate 60.000.000 bytes file.
for($i = 0; $i < 60000000; $i++) {
echo "A";
}
3. [代码]示例2 跳至 [2] [3] [全屏预览]
<?php
//throttler类太长可以到:http://www.codepearl.com/files/160.html下载
require("./throttler.php");
// create new config
$config = new ThrottleConfigBySize();
// enable burst rate for first 500000 bytes, after that revert to the standard transfer rate
$config->burstSize = 500000;
// set burst transfer rate to 50000 bytes/second
$config->burstLimit = 50000;
// 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);
//http://www.codepearl.com
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"test.txt\"");
header("Content-Length: 60000000");
// generate 60.000.000 bytes file.
for($i = 0; $i < 60000000; $i++) {
echo "A";
}
- 上一篇:比较完整的留言板代码,添加注释,易懂
- 下一篇:在中间部分截取指定大小图片
精彩图集
精彩文章






