Gearman+perl

client.pl

####################
#client.pl
####################

#!/usr/bin/perl -w
use strict;
use Gearman::Client;

my $client = new Gearman::Client;
$client->job_servers('127.0.0.1');

my $time = time;

for ( 1..5 ) {
    $client->dispatch_background('do', $_);
}

print "time cost: " . (time - $time) . " seconds \n";

worker.pl

####################
#worker.pl
####################

#!/usr/bin/perl -w
use strict;
use Gearman::Worker;

my $worker = new Gearman::Worker;
$worker->job_servers('127.0.0.1');
$worker->register_function(do => \&do);
$worker->work while 1;

sub do{
    my $job = shift;
    my $job_id = $job->arg;

    # get job id and do the job
    # xxx

    print "pid: $$, job id: $job_id" . "\n";
}

这篇文章: 有用 无用