may be sth like this will work?!
#!/usr/bin/perl
use IO::Select;
use IO::Socket::INET;
use ResourcePool;
use ResourcePool::Factory::DBI;
use ResourcePool::Command::DBI::Execute;
# Initialize parameter ------------------------------------------------
$debug= 1;
$main = new IO::Socket::INET (
LocalHost => '127.0.0.1',
LocalPort => 6000,
Listen => 5,
Proto => 'tcp',
Reuse => 1 ) || die $!;
$zero = chr(0);
$/ = $zero;
$\ = $zero;
$| = 1;
my $dsn = "DBI:mysql:DBNAME;your.server#2;3306";
my $username = "xxx";
my $passwd = "zzz";
# Initialize Ressource ------------------------------------------------
my $factory = ResourcePool::Factory::DBI->new(
$dsn,
$username,
$passwd);
my $pool = ResourcePool->new($factory, MaxTry => 3);
# Initialize IO::Select ------------------------------------------------
$handles = new IO::Select();
$handles->add($main);
print "Starting listening cycle\n" if($debug > 0);
LISTEN: while (1)
{
($pending) = IO::Select->select($handles, undef, undef, 60);
foreach $sock (@$pending)
{
if ($sock == $main)
{
$num++;
print "Got new connection: $num from ".$sock->sockhost()."\n" if($debug > 0);
my $newsock = $sock->accept();
$newsock->autoflush();
$number{$newsock} = $num;
$handles->add($newsock);
} else {
my $buf = <$sock>;
if ($buf)
{
print "Existing socket $number{$sock} is pending: " if($debug > 0);
chomp $buf;
print "$buf\n" if($debug > 0);
my $cmd = ResourcePool::Command::DBI::Execute->new();
$pool->execute($cmd, $buf);
} else {
print "Socket $number{$sock} is gone.\n" if($debug > 0);
$handles->remove($sock);
}
}
}
}
In reply to Re: how can N client.pl connect to one deamon serving mysql
by saxman25
in thread how can N client.pl connect to one deamon serving mysql
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |