#!/usr/bin/perl

use strict;
use LWP::UserAgent;
use threads;
use threads::shared;

my @data :shared = ();
my $start :shared = $ARGV[2];
my $promo_url :shared = $ARGV[1];

my $ua = LWP::UserAgent->new();
   $ua->timeout(20); 
   
open(AA, "<$ARGV[0]");
@data = <AA>;
close(AA);

@data = reverse(@data);

threads->create(\&make_ref) for (1..10);
$_->join for threads->list;

sub make_ref
{
    while (@data) {
        my $str = shift @data || return;
		chomp $str;
	
		my ($i, $url) = split(/,/, $str);
	
		#next if $i > $start;
	
		print "$i : Ref $url...";
		for (my $j = 0; $j < 2; $j++) {
			my $req = HTTP::Request->new(HEAD => "http://$url");
			   $req->header("Referer" => "http://$promo_url");
			my $res = $ua->request($req);
		}
		print "OK\n";
	}
}

1;

