Last active
December 23, 2015 08:46
-
-
Save aero/0558184c8264b0c0e856 to your computer and use it in GitHub Desktop.
Solving Mojolicious fork-based multi-processes daemon(eg. hypnotoad) Mojo::mysql connection timeout close issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mojolicious::Lite; | |
use Mojo::mysql; | |
helper db => sub { | |
state $db = Mojo::mysql->new('mysql://user:pass@/task')->db; | |
if (! $db->ping ) { | |
$db->dbh( $db->dbh->clone() ) or die "cannot connect to db"; | |
} | |
return $db; | |
}; | |
get '/list' => sub { | |
my $c = shift; | |
my $rs = $c->db->query('select count(*) as count from list'); | |
my $rs_count = $rs->hash->{count}; | |
$c->render( text => $rs_count ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment