题
是否有任何的Perl模块可供下载限制?我想下载特定文件,但限制下载速率KB / sec的特定号码。
解决方案
看起来像WWW ::卷曲和CURLOPT_MAX_RECV_SPEED_LARGE选项是 你想要什么:
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';
use WWW::Curl::Easy;
# Setting the options
my $curl = WWW::Curl::Easy->new;
$curl->setopt(CURLOPT_HEADER,1);
$curl->setopt(CURLOPT_URL, 'http://www.google.com');
$curl->setopt(CURLOPT_MAX_RECV_SPEED_LARGE, 1);
my $response_body;
open my $fh, ">", \$response_body or die; # presumably this can be a real file as well.
$curl->setopt(CURLOPT_WRITEDATA,$fh);
my $ret = $curl->perform;
die 'Error: '. $curl->strerror($ret) if $ret;
my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);
say "Received response: $response_body";
在这个例子中,我们下载谷歌以每秒一个字节。非常 慢。
其他提示
不限于Perl和不限于特定的协议的技术是使用滴流:
滴流是便携式轻量级用户空间带宽整形器。它可以在协作模式下运行(与细流一起)或在单机模式下。
另请参见你如何节流在C插座连接的带宽?
这将是很好至打包这种技术,因为一个Perl模块(例如子类IO ::手柄),但我不知道的一个。
不隶属于 StackOverflow