2009-02-12 26 views

回答

6

看起来像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"; 

在这个例子中,我们以每秒一个字节下载谷歌。很慢 慢。

3

的技术不限于Perl和不限于特定的协议是使用trickle

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

How do you throttle the bandwidth of a socket connection in C?

见这将是不错的打包这种技术,因为Perl模块(例如一个继承IO ::手柄),但我不知道一个。