以下の内容はhttps://hiratara.hatenadiary.jp/entry/20110122/1295711939より取得しました。


DBIとforkとInactiveDestroy

@lestrratさんが教えてくれたことのメモ。

以下のコードはエラーとなります*1

use strict;
use warnings;
use DBI;

my $dbh = DBI->connect('DBI:mysql:mysql', 'root', 'password') or die DBI->errstr;

my $pid;
if ($pid = fork) {
	# NOP in the parent
	waitpid $pid => 0;
} elsif (defined $pid) {
	# NOP in the child
	exit;
} else {
	die "Couldn't fork, stopped";
}

print $dbh->selectrow_array('select count(*) from user'), "\n";

【実行結果】
DBD::mysql::db selectrow_array failed: MySQL server has gone away at xxxx.pl line 18.

InactiveDestroyをちゃんと設定してないだけとか?

@lestrrat

仰せの通りでした。。。去年秋以降くらいの新しいDBIを使ってるなら、接続後に $dbh->{AutoInactiveDestroy} = 1 しとけばOKです。古いDBIなら、fork直後に子プロセス側で $dbh->{InactiveDestroy} = 1 にするといいです。podにも書いてます。

*1:こちらのエントリと同じ内容。




以上の内容はhttps://hiratara.hatenadiary.jp/entry/20110122/1295711939より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14