(公司有个需求,防止人不停地下载,在别人的网站里看到的) 以下翻译来自Google 这个类可以用来限制下载文件的速度。 它拦截PHP脚本的输出提供给浏览器设置一个缓冲处理,被称为每次定的字节数。 类自最后一次测量的时间PHP输出缓冲液冲洗,并保持一段时间,
(公司有个需求,防止人不停地下载,在别人的网站里看到的)
源码与演示:源码出处 演示出处
<?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"; }
<?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"; }