가상 호스트에서 mod_perl2가 실행 중이고 서버로드를 처리하기위한 요청간에 mysql 연결을 영구히 유지하려고합니다. 주제에 관한 모든 설명서와 책을 읽었으며 mod_perl2 웹 응용 프로그램의이 베어 본 구현이 "깨졌습니다!"라고 대답하는 이유는 여전히 알 수 없습니다.왜 내 패키지 (our'd) 변수가 PerlChildInitHandler와 PerlResponseHandler (mod_perl2) 사이에서 지워 집니까?
package Test;
use strict;
use warnings;
use Apache2::Const;
use Carp qw{croak};
use DBI;
our $mysql_handle;
sub handler {
print "Content-Type: text/plain\n\n";
print (defined $mysql_handle ? "It's defined!" : "It's broken!");
return Apache2::Const::OK;
}
sub child_init {
my ($db, $host, $port, $user, $pass)
= qw{app_db localhost 3306 app_user app_pass};
$mysql_handle
= DBI->connect("dbi:mysql:database=$db;host=$host;port=$port", $user, $pass)
or croak("Failed to establish a connection with mysqld: $DBI::errstr");
return Apache2::Const::OK;
}
1;
이것은 매우 이상하며 전혀 이해가되지 않습니다. 마치 $ mysql_handle이 어휘 적으로 범위가 지정되어있는 것처럼 보입니다. 제발, 나에게 이걸 설명 할 수 있니?