NAME
AnyEvent::MySQL::ConnPool
DESCRIPTION
Adds additional method "pool_connect" to AnyEvent::MySQL package.
SYNOPSIS
Similar to AnyEvent::MySQL->connect();
use AnyEvent;
use AnyEvent::MySQL;
use AnyEvent::MySQL::ConnPool;
my $connpool = AnyEvent::MySQL->connect_pool(
"DBI:mysql:database=test;host=127.0.0.1;port=3306",
"ptest",
"pass", {
PrintError => 1,
PoolSize => 10,
CheckInterval => 5,
},
sub {
my($dbh) = @_;
if( $dbh ) {
warn "Connect success!";
$dbh->pre_do("set names latin1");
$dbh->pre_do("set names utf8");
}
else {
warn "Connect fail: $AnyEvent::MySQL::errstr ($AnyEvent::MySQL::err)";
$end->send;
}
}
);
METHODS
- connect_pool
-
Returns connected AnyEvent::ConnPool object. All options for connect_pool are similar to the AnyEvent::MySQL->connect method. But pool accepts additional options in parameters hashref(4th parameter).
AnyEvent::MySQL->connect_pool($dsn, $user, $password, {PoolSize => 5, CheckInterval => 10}, $callback);
PoolSize => how many connections should be created. 5 connections by default.
CheckInterval => Interval for ping connections. 10 seconds by default.