코드 조각. 스크립트는 악마가되어야하고, 두 개의 데이터베이스에 연결되어야하며, 끊임없이 일부 필드를 확인해야합니다. 그러나 나는 오류를 받는다. 로그 DBD::Pg::st execute failed: SSL connection has been closed unexpectedly at ./remote_imap.pl line 55.
실행 실패 perl dbi
로그 데이터베이스가 비어 있습니다.
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;
}
펄 v5.18.2 의 PostgreSQL V8.4은
무슨 문제가 될 수 있을까?
고유 한 코딩 표준에 만족할 수도 있지만 다른 사람이 코드를 도울 수있게하려면 평소보다 더 자주 작성하는 것이 좋습니다. 이것은 나를 위해 거의 읽을 수 없다. – Borodin
말한 코드 섹션을 제거하면 닫히지 않은'foreach' 문이 남게되어 코드가 컴파일되지 않습니다. 'foreach '전체를 제거했다는 뜻입니까? – Borodin
예, 모두 전체 'foreach'. – user3751471