#!/usr/bin/perl -w use threads; use DBI; use IPC::SysV qw(IPC_PRIVATE S_IRWXU S_IRWXG S_IRWXO IPC_CREAT); use IPC::Msg; use DBIx::Threaded; use Thread::Queue::Duplex; # SysV IPC message queue $msg = new IPC::Msg(0x4142678a, S_IRWXU | S_IRWXG | S_IRWXO | IPC_CREAT); $msgtype=2; # creating database handle $dbh = DBIx::Threaded->connect("DBI:mysql:database=$DataBaseName;host=$DataBaseHost","$DataBaseUser","$DataBasePass", { RaiseError => 1, AutoCommit => 0, }) || die "Unable to connect to $DataBaseHost because $DBI::errstr"; # useless statement handle, there must be at leas one existing otherwise $dbh is destroyed after the first cycle $sth_zb = $dbh->prepare("SELECT * FROM testcallapp"); # taking data from message queue while ($msg->rcv($buf,256)) { # printing actually living threads foreach $thr (threads->list) { my $tred = $thr->tid; print "DEBUG: $tred\n"; } # creating enw thread threads->new(\&vlakno, $buf); print "DEBUG: $buf !\n"; } # subroutine for a thread sub vlakno { my ($buffer) = @_; # chopping buffer for data my @sysv = split(/,/, $buffer); my $natv2 = $sysv[0]; my $v2 = $sysv[1]; # statement handle, finding out, if data are in database my $sth = $dbh->prepare("SELECT host FROM ... "); $sth->execute(); $sth->bind_columns(\$host); # writing data from database while($sth->fetch()) { print "DEBUGGER: $host\n"; } # finishing the statement handle $sth->finish; }