Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何限制Perl程序中的下载?_Perl_Download_Throttling - Fatal编程技术网

如何限制Perl程序中的下载?

如何限制Perl程序中的下载?,perl,download,throttling,Perl,Download,Throttling,是否有任何Perl模块可用于下载限制?我想下载某个文件,但将下载速率限制为特定的KB/秒。一种不限于Perl且不限于特定协议的技术是使用: 涓流是一款便携式轻量级用户空间带宽整形器。它可以在协作模式(与涓流模式一起)或独立模式下运行 另见 将此技术打包为Perl模块(例如,子类IO::Handle)会很好,但我不知道有这样一个模块。看起来像WWW::Curl,而CURLOPT_MAX_RECV_SPEED_LARGE选项是 你想要什么: #!/usr/bin/env perl use stri

是否有任何Perl模块可用于下载限制?我想下载某个文件,但将下载速率限制为特定的KB/秒。

一种不限于Perl且不限于特定协议的技术是使用:

涓流是一款便携式轻量级用户空间带宽整形器。它可以在协作模式(与涓流模式一起)或独立模式下运行

另见


将此技术打包为Perl模块(例如,子类IO::Handle)会很好,但我不知道有这样一个模块。

看起来像WWW::Curl,而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";
在本例中,我们以每秒一个字节的速度下载Google。非常 慢点