一段代码。脚本必须成为恶魔,连接到两个数据库,并不断检查一些字段。但我收到错误。记录DBD::Pg::st execute failed: SSL connection has been closed unexpectedly at ./remote_imap.pl line 55.
数据库日志为空。
my $daemon = Proc::Daemon->new;
Proc::Daemon::Init({
work_dir => '/home/olex/develop',
child_STDOUT => '/home/olex/develop/output.file',
child_STDERR => '+>>debug.txt',
pid_file => 'remote_imap.pid'
});
if (Proc::PID::File->running({dir=>'/home/olex/develop', verify=>1})) {
print "Already running\n";
exit 0;
}
my @kids = (0..3);
my @childs;
my $kid_pid;
my ($dbname,$dbuser,$dbpass) = ('***','**','***');
my ($dbhost, $dbhost_ag, $dbport) = ('192.168.0.**', '192.168.0.**', '5432');
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport", $dbuser, $dbpass,
{ RaiseError => 1
, AutoCommit => 0 })
or die $DBI::errstr;
my $dbh_ag = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost_ag;port=$dbport", $dbuser, $dbpass,
{ RaiseError => 1
, AutoCommit => 0 })
or die $DBI::errstr;
my $status;
my $continue = 1;
$SIG{TERM} = sub { $continue = 0 };
while ($continue) {
foreach $kid_pid (@kids) {
$status = $daemon->Status($kid_pid);
if (!$status){
$kid_pid = $daemon->Init( {
work_dir => '/home/olex/develop',
pid_file => 'kid_pid.pid',
exec_command => 'perl /home/olex/develop/remote_imapd.pl',
} );
}
push @childs, $kid_pid;
}
my @params;
$params[0] = 2; #DB_USERS_REMOTE_STATUS_PROCESSING
$params[1] = 1; #DB_IN_QUEUE_STATUS_NEW
my $childs_proc = join(',', @childs);
# Fetch new records
my $q = "select id from queues.queue_in where status=? and user_remote_id>? order by date_create asc";
my $sth_ag = $dbh_ag->prepare($q);
my $rv_ag = $sth_ag->execute($params[1], 0);
my $id = $sth_ag->fetchrow_array();
print $id, "\n";
*
*
*
sleep(0.0001);
}
$dbh->disconnect();
$dbh_ag->disconnect();
如果我删除此代码,请正常工作。
foreach $kid_pid (@kids) {
$status = $daemon->Status($kid_pid);
if (!$status){
$kid_pid = $daemon->Init( {
work_dir => '/home/olex/develop',
pid_file => 'kid_pid.pid',
exec_command => 'perl /home/olex/develop/remote_imapd.pl',
} );
}
push @childs, $kid_pid;
}
perl v5.18.2 postgresql v8.4
可能是什么问题?
答案 0 :(得分:1)
分叉孩子后台程序后打开数据库。根据我的经验,数据库连接几乎从不存在于分支中。
这就是为什么当你移除叉子时它会起作用。