#!/usr/bin/perl use Net::DNS; use DBI; use 5.10.0; use threads; use threads::shared; use Date::Calc qw(Delta_Days); use Net::DNS::Sendmail; use DBIx::Threaded; #use diagnostics; $| = 1; my $thread_no = shift; my $host = "localhost"; my $database = "test"; my $user = "root"; my $password = ""; my (@date) = (localtime)[5,4,3]; $date[1]++; $date[0] += 1900; my $dbh_t = DBIx::Threaded->connect("DBI:mysql:database=$database;host=$host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host", $user, $password); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_list"); $sth->execute(); my $counter = 0; while (my @row = $sth->fetchrow_array()) { my $id = $row[0]; my $domain = $row[1]; my $created = $row[2]; next unless $row[0..3]; my $thr = threads->create(mx_lookup,$id,$domain,$created) unless $counter >= $thread_no; $thr->detach && $counter++ if $thr; } $dbh_t->close_all(); $dbh->disconnect(); sub mx_lookup { my $id = shift; my $domain = shift; my $date_c = shift; my @date_c = split /-/, $date_c; my $delta = Delta_Days(@date_c,@date); if ($delta <= 30) { my $sth = $dbh_t->dbix_threaded_start_prepare("select max(id),domain_id,changed_from,changed_to,date from mx_history where domain_id=$id"); #this is where the script fails $sth->dbix_threaded_start(); my @row = $sth->fetchrow_array(); my $last_mx = $row[3]; $sth->finish(); } }