blog20100901

2013/08/20 - プログラミング言語 Perl にまつわる etc. - Perl monger
参考 : perldoc, perldoc.jp, search.cpan.org, perldoc.perl.org ...
「 初めての Perl 第 6 版 」(オライリー・ジャパン発行 ISBN978-4-87311-567-2) 」
「 続・初めての Perl 改訂版 」(オライリー・ジャパン発行 ISBN4-87311-305-9) 」
「 Effective Perl 第 2 版 」(翔泳社発行 ISBN978-4-7981-3981-4) 」 ... etc,.

Perl Perl_7 mod_perl 翻訳 Web Server

Perl mp2 翻訳 サーバライフサイクル ハンドラ (d195)

目次 - Perl Index


Theme



Perl について、復習を兼ねて断片的な情報を掲載して行く連載その d195 回。

今回は、「 mod_perl Home / The mod_perl Web Site / Documentation / mod_perl 2.0 Documentation / User's guide / Part V: mod_perl Handlers / Server Life Cycle Handlers 」を翻訳して確認します。

正確な内容は 原文 を確認してください。誤解や誤訳がある場合はご指摘ください。




説明 : Description


This chapter discusses server life cycle and the mod_perl handlers participating in it.

このチャプタはサーバライフサイクルとそれに参加する mod_perl ハンドラを論じます。


サーバライフサイクル : Server Life Cycle


The following diagram depicts the Apache 2.0 server life cycle and highlights which handlers are available to mod_perl 2.0:

次のダイアグラムは Apache 2.0 のサーバライフサイクルを描きどのハンドラが mod_perl 2.0 で利用可能になるかを強調しています:

server life cycle
A quotation from Server Life Cycle Handlers


Apache 2.0 starts by parsing the configuration file. After the configuration file is parsed, the PerlOpenLogsHandler handlers are executed if any. After that it's a turn of PerlPostConfigHandler handlers to be run. When the post_config phase is finished the server immediately restarts, to make sure that it can survive graceful restarts after starting to serve the clients.

Apache 2.0 は構成ファイルをパースすることでスタートします。構成ファイルがパースされた後, PerlOpenLogsHandler ハンドラがあれば実行されます。その後は PerlPostConfigHandler ハンドラが実行されるターンです。post_config フェーズが終了するとサーバはすぐにリスタートして, それがクライアントへのサーブが開始された後にグレースフルリスタートを乗り切れるかを確認します。
When the restart is completed, Apache 2.0 spawns the workers that will do the actual work. Depending on the used MPM, these can be threads, processes or a mixture of both. For example the worker MPM spawns a number of processes, each running a number of threads. When each child process is started PerlChildInitHandler handlers are executed. Notice that they are run for each starting process, not a thread.

リスタートが完了したとき, Apache 2.0 は実際の作業を行う worker を生み出します。利用している MPM に応じて, それはスレッド, プロセスまたは両方のミックスになります。例えば worker MPM はいくつかのプロセスを生み出し, それぞれがいくつかのスレッドを実行します。各 child (# 子) プロセスがスタートされたとき PerlChildInitHandler ハンドラが実行されます。これはスレッドではなく, 各スタートプロセスで実行されることに注意してください。
From that moment on each working thread processes connections until it's killed by the server or the server is shutdown.

その瞬間からサーバによりそれが kill されるかサーバがシャットダウンするまで各ワーキングスレッドはコネクションを処理します。


スタートアップフェーズのデモモジュール : Startup Phases Demonstration Module


Let's look at the following example that demonstrates all the startup phases:

すべてのスタートアップフェーズを実演する次の例を見てみましょう:

#file:MyApache2/StartupLog.pm
#----------------------------
package MyApache2::StartupLog;

use strict;
use warnings;

use Apache2::Log ();
use Apache2::ServerUtil ();

use Fcntl qw(:flock);
use File::Spec::Functions;

use Apache2::Const -compile => 'OK';

my $log_path = catfile Apache2::ServerUtil::server_root,
"logs", "startup_log";
my $log_fh;

sub open_logs {
my ($conf_pool, $log_pool, $temp_pool, $s) = @_;

$s->warn("opening the log file: $log_path");
open $log_fh, ">>$log_path" or die "can't open $log_path: $!";
my $oldfh = select($log_fh); $| = 1; select($oldfh);

say("process $$ is born to reproduce");
return Apache2::Const::OK;
}

sub post_config {
my ($conf_pool, $log_pool, $temp_pool, $s) = @_;
say("configuration is completed");
return Apache2::Const::OK;
}

sub child_init {
my ($child_pool, $s) = @_;
say("process $$ now exits");
return Apache2::Const::OK;
}

sub say {
my ($caller) = (caller(1))[3] =~ /([^:]+)$/;
if (defined $log_fh) {
flock $log_fh, LOCK_EX;
printf $log_fh "[%s] - %-11s: %s\n",
scalar(localtime), $caller, $_[0];
flock $log_fh, LOCK_UN;
}
else {
# when the log file is not open
warn __PACKAGE__ . " says: $_[0]\n";
}
}

my $parent_pid = $$;
END {
my $msg = "process $$ is shutdown";
$msg .= "\n". "-" x 20 if $$ == $parent_pid;
say($msg);
}

1;

And the httpd.conf configuration section:

それから httpd.conf の構成セクションです:

<IfModule prefork.c>
StartServers 4
MinSpareServers 4
MaxSpareServers 4
MaxClients 10
MaxRequestsPerChild 0
</IfModule>

PerlModule MyApache2::StartupLog
PerlOpenLogsHandler MyApache2::StartupLog::open_logs
PerlPostConfigHandler MyApache2::StartupLog::post_config
PerlChildInitHandler MyApache2::StartupLog::child_init
PerlChildExitHandler MyApache2::StartupLog::child_exit

When we perform a server startup followed by a shutdown, the logs/startup_log is created if it didn't exist already (it shares the same directory with error_log and other standard log files), and each stage appends to that file its log information. So when we perform:

私たちがサーバのスタートアップと続いてシャットダウンを実行したとき, logs/startup_log がまだ存在しないなら作成され (error_log や他の標準ログファイルと同じディレクトリを共有します), 各ステージはログ情報をそのファイル追加します。ですから私たちがこれを実行するとき:

% bin/apachectl start && bin/apachectl stop

the following is getting logged to logs/startup_log:

次のものが logs/startup_log に記録されます:

[Sun Jun 6 01:50:06 2004] - open_logs : process 24189 is born to reproduce
[Sun Jun 6 01:50:06 2004] - post_config: configuration is completed
[Sun Jun 6 01:50:07 2004] - END : process 24189 is shutdown
--------------------
[Sun Jun 6 01:50:08 2004] - open_logs : process 24190 is born to reproduce
[Sun Jun 6 01:50:08 2004] - post_config: configuration is completed
[Sun Jun 6 01:50:09 2004] - child_init : process 24192 is born to serve
[Sun Jun 6 01:50:09 2004] - child_init : process 24193 is born to serve
[Sun Jun 6 01:50:09 2004] - child_init : process 24194 is born to serve
[Sun Jun 6 01:50:09 2004] - child_init : process 24195 is born to serve
[Sun Jun 6 01:50:10 2004] - child_exit : process 24193 now exits
[Sun Jun 6 01:50:10 2004] - END : process 24193 is shutdown
[Sun Jun 6 01:50:10 2004] - child_exit : process 24194 now exits
[Sun Jun 6 01:50:10 2004] - END : process 24194 is shutdown
[Sun Jun 6 01:50:10 2004] - child_exit : process 24195 now exits
[Sun Jun 6 01:50:10 2004] - child_exit : process 24192 now exits
[Sun Jun 6 01:50:10 2004] - END : process 24192 is shutdown
[Sun Jun 6 01:50:10 2004] - END : process 24195 is shutdown
[Sun Jun 6 01:50:10 2004] - END : process 24190 is shutdown
--------------------

First of all, we can clearly see that Apache always restart itself after the first post_config phase is over. The logs show that the post_config phase is preceded by the open_logs phase. Only after Apache has restarted itself and has completed the open_logs and post_config phase again, the child_init phase is run for each child process. In our example we have had the setting StartServers=4, therefore you can see four child processes were started.

まず最初に, 私たちは Apache が常に最初の post_config フェーズが終了したあとで自身をリスタートすることをはっきりみえます。ログは post_config フェーズに先行して open_logs フェーズがあることを示します。Apache が自身でリスタートして再度 open_logs と post_config フェーズが完了した後でのみ, chidl_init フェーズが各 child プロセスのために実行されます。私たちの例で私たちは StartServers=4 の設定を持っていますので, あなた 4 つの child プロセスがスタートしたことを見られます。
Finally you can see that on server shutdown, the child_exit phase is run for each child process and the END {} block is executed by the parent process and each of the child processes. This is because that END block was inherited from the parent on fork.

最後にあなたはサーバのシャットダウンで, child_exit フェーズが各 child プロセスのために走り END {} ブロックが各 child プロセスと parent プロセスにより実行されたことを見ます。これは END ブロックが fork で parent から継承されるからです。
However the presented behavior varies from MPM to MPM. This demonstration was performed using prefork mpm. Other MPMs like winnt, may run open_logs and post_config more than once. Also the END blocks may be run more times, when threads are involved. You should be very careful when designing features relying on the phases covered in this chapter if you plan support multiple MPMs. The only thing that's sure is that you will have each of these phases run at least once.

しかし提供される振る舞いは MPM ごとに様々です。このドキュメントは prefork mpm を使って実行されています。他の winnt のような MPM は, open_logs と post_config を 1 度以上実行するかもしれません。また END ブロックはスレッドが関与したときに, より多く実行される可能性があります。あなたが複数の MPM をサポートすることを計画しているならあなたはこのチャプタでカバーされたフェーズに関連する機能を設計するときにかなり注意したほうがよいでしょう。唯一確かなことはあなたはこれら各フェーズを少なくとも一度は実行することです。
Apache also specifies the pre_config phase, which is executed before the configuration files are parsed, but this is of no use to mod_perl, because mod_perl is loaded only during the configuration phase.

Apache は構成ファイルがパースされる前に実行される, pre_config フェーズも指定しますが, mod_perl は構成フェーズの間でのみロードされるので, これは mod_perl には役立ちません。
Now let's discuss each of the mentioned startup handlers and their implementation in the MyApache2::StartupLog module in detail.

では言及した各スタートアップハンドラと MyApache2::StartupLog モジュールでのそれらの実装を詳しく論じましょう。


PerlOpenLogsHandler


The open_logs phase happens just before the post_config phase.

open_logs フェーズは post_config フェーズの直前に発生します。
Handlers registered by PerlOpenLogsHandler are usually used for opening module-specific log files (e.g., httpd core and mod_ssl open their log files during this phase).

PerlOpenLogsHandler によって登録されたハンドラは通常モジュール固有のログファイルをオープンするために使われます (e.g., httpd core と mod_ssl はこのフェーズの間でそれらのログファイルをオープンします)。
At this stage the STDERR stream is not yet redirected to error_log, and therefore any messages to that stream will be printed to the console the server is starting from (if such exists).

このステージで STDERR ストリームはまだ error_log にリダイレクトされていません, したがってそのストリームへのメッセージはサーバがスタートしたコンソールに出力されます (それが存在するなら)。
This phase is of type RUN_ALL.

このフェーズが RUN_ALL のタイプです。
The handler's configuration scope is SRV.

ハンドラの構成スコープは SRV です。

Arguments


The open_logs handler is passed four arguments: the configuration pool, the logging stream pool, the temporary pool and the main server object.

open_logs ハンドラは 4 つの引数が渡されます: 構成プール, ロギングストリームプール, テンポラリプールそれからメインサーバオブジェクトです。
The pool arguments are:

プール引数はこれです:


  • $conf_pool is the main process sub-pool, therefore its life-span is the same as the main process's one. The main process is a sub-pool of the global pool.

    $conf-pool はメインプロセスのサブプールなので, そのライフスパンはメインプロセスのものと同じです。メインプロセスはグローバルプールのサブプールです。


  • $log_pool is a global pool's sub-pool, therefore its life-span is the same as the Apache program's one.

    $log_pool はグローバルプールのサブプールなので, そのライフスパンは Apache プログラムのものと同じです。
    META: what is it good for if it lives the same life as conf pool?

    META: もしそれが conf プールと同じライフの生活だったらなんの意味がある ?


  • $temp_pool is a $conf_pool subpool, created before the config phase, lives through the open_logs phase and get destroyed after the post_config phase. So you will want to use that pool for doing anything that can be discarded before the requests processing starts.

    $temp_pool は $conf_pool のサブプールで, 構成フェーズの前に作成され, open_logs フェーズを生き延びて post_config フェーズの後で破棄されます。ですからあなたはリクエストプロセスがスタートする前に破棄できるすべてことを行うためにこのプールを使います。


All three pool arguments are instances of APR::Pool.

3 つのプール引数はすべて APR::Pool のインスタンスです。
$s is the base server object (an instance of Apache2::ServerRec).

$s はベースサーバのオブジェクトです (Apache2::ServerRec のインスタンス)。


Return


The handler should return Apache2::Const::OK if it completes successfully.

このハンドラが正常に完了すると Apache2::Const::OK を返すはずです。


Examples



sub open_logs {
my ($conf_pool, $log_pool, $temp_pool, $s) = @_;

$s->warn("opening the log file: $log_path");
open $log_fh, ">>$log_path" or die "can't open $log_path: $!";
my $oldfh = select($log_fh); $| = 1; select($oldfh);

say("process $$ is born to reproduce");
return Apache2::Const::OK;
}

In our example the handler opens a log file for appending and sets the filehandle to unbuffered mode. It then logs the fact that it's running in the parent process.

私たちの例でハンドラは log ファイルを追加するためにオープンしファイルハンドルを非バッファモードにセットします。それからそれが parent プロセスで走っているという事実をログします。
As you've seen in the example this handler is configured by adding to the top level of httpd.conf:

あなたが例示で見たとおりこのハンドラは httpd.conf のトップレベルに追加することで構成されます。

PerlOpenLogsHandler MyApache2::StartupLog::open_logs

This handler can be executed only by the main server. If you want to traverse the configured virtual hosts, you can accomplish that using a simple loop. For example to print out the configured port numbers do:

このハンドラはメインサーバでのみ実行できます。あなたが構成されたバーチャルホストをトラバース (# 横断) したい場合, あなたはシンプルなループを使ってそれをやり遂げることができます。例えば構成されたポート番号を出力するにはこれを行います:

use Apache2::ServerRec ();
# ...
sub open_logs {
my ($conf_pool, $log_pool, $temp_pool, $s) = @_;

my $port = $s->port;
warn "base port: $port\n";
for (my $vs = $s->next; $vs; $vs = $vs->next) {
my $port = $vs->port;
warn "vhost port: $port\n";
}
return Apache2::Const::OK;
}



PerlPostConfigHandler


The post_config phase happens right after Apache has processed the configuration files, before any child processes were spawned (which happens at the child_init phase).

post_config フェーズは Apache が構成ファイルを処理した直後で, child プロセスが生み出される (これは child_init フェーズで発生) 前に発生します。
This phase can be used for initializing things to be shared between all child processes. You can do the same in the startup file, but in the post_config phase you have an access to a complete configuration tree (via Apache2::Directive).

このフェーズはすべての child プロセス間で共有されるものを初期化するために使えます。あなたはスタートアップファイルで同じことをできますが, post_config フェーズであなたは完全な構成ツリーへのアクセスをもてます (via Apache2::Directive)。
This phase is of type RUN_ALL.

このフェーズが RUN_ALL のタイプです。
The handler's configuration scope is SRV.

ハンドラの構成スコープは SRV です。


Arguments


Arguments are exactly as for PerlOpenLogsHandler.

引数は PerlOpenLogsHandler とまったく同じです。


Return


If the handler completes successfully it should return Apache2::Const::OK.

ハンドラが正常に完了したらそれは Apache2::Const::OK をリターンするはずです。


Examples


In our MyApache2::StartupLog example we used the post_config() handler:

私たちの例 MyApache2::StartupLog で私たちは post_config() ハンドラをこのように使いました:

sub post_config {
my ($config_pool, $log_pool, $temp_pool, $s) = @_;
say ("configuration is completed");
retunr Apache2::Const::OK;
}

As you can see, its arguments are identical to the open_logs phase's handler. In this example handler we don't do much, but logging that the configuration was completed and returning right away.

あなたが見たとおり, その引数は open_logs フェーズのハンドラと同一です。この例のハンドラで私たちは多くを行わず, その構成が完了したことをログしてすぐにリターンします。
As you've seen in the example this handler is configured by adding to httpd.conf:

あなたが例示で見たようにこのハンドラは httpd.conf に追加することで構成されます:

PerlPostConfigHandler MyApache2::StartupLog::post_config

Everything that applies to PerlOpenLogsHandler identically applies to this handler.

PerlOpenLogsHandler に適用されるものがすべて同様にこのハンドラに適用されます。
The add_version_component() includes another useful example.

add_version_component() は他の便利な例を含んでいます。


PerlChildInitHandler


The child_init phase happens immediately after the child process is spawned. Each child process (not a thread!) will run the hooks of this phase only once in their life-time.

child_init フェーズは child プロセスが生み出された後すぐに発生します。各 child プロセス (スレッドではない !) はそのライフタイムで 1 度のみこのフェーズのフックを実行します。
In the prefork MPM this phase is useful for initializing any data structures which should be private to each process. For example Apache::DBI pre-opens database connections during this phase and Apache2::Resource sets the process' resources limits.

prefork MPM でこのフェーズは各プロセスにプライベートになるべきデータ構造を初期化するのに役立ちます。例えば Apache::DBI はこのフェーズの間でデータベースコネクションを事前にオープンして Apache2::Resource はプロセスのリソースリミットをセットします。
This phase is of type VOID.

このフェーズは VOID のタイプです。
The handler's configuration scope is SRV.

このハンドラの構成スコープは SRV です。


Arguments


The child_init() handler is passed two arguments: the child process pool (APR::Pool) and the server object (Apache2::ServerRec).

child_init() ハンドラは 2 つの引数を渡されます: child プロセスプール (APR::Pool) とサーバオブジェクト (Apache2::ServerRec)。


Return


If the handler completes successfully it should return Apache2::Const::OK.

ハンドラが正常に完了したら Apache2::Const::OK をリターンするはずです。


Examples


In our MyApache2::StartupLog example we used the child_init() handler:

私たちの例 MyApache2::StartupLog で私たちは child_init() ハンドラをこのように使いました:

sub child_init {
my ($child_pool, $s) = @_;
say("process $$ is born to serve");
return Apache2::Const::OK;
}

The example handler logs the pid of the child process it's run in and returns.

この例のハンドラはそれが実行されている child プロセスの pid をログしてリターンします。
As you've seen in the example this handler is configured by adding to httpd.conf:

あなたが例示で見たとおりこのハンドラは http.conf に追加することで構成されます:

PerlChildInitHandler MyApache2::StartupLog::child_init



PerlChildExitHandler


Opposite to the child_init phase, the child_exit phase is executed before the child process exits. Notice that it happens only when the process exits, not the thread (assuming that you are using a threaded mpm).

child_init フェーズとは逆に, child_exit フェーズは child プロセスが終了する前に実行されます。これはスレッド (あなたがスレッド化された mpm を使っていると仮定して) ではなく, プロセスが終了したときにのみ発生することに注意してください。
This phase is of type RUN_ALL.

このフェーズは RUN_ALL のタイプです。
The handler's configuration scope is SRV.

このハンドラの構成スコープは SRV です。


Arguments


The child_exit() handler accepts two arguments: the child process pool (APR::Pool) and the server object (Apache2::ServerRec).

child_exit() ハンドラは 2 つのハンドラを受けいれます: child プロセスプール (APR::Pool) とサーバオブジェクト (Apache2::ServerRec) です。


Return


If the handler completes successfully it should return Apache2::Const::OK.

このハンドラが正常に完了したら Apache2::Const::OK をリターンするはずです。


Examples


In our MyApache2::StartupLog example we used the child_exit() handler:

私たちの例 MyApache2::StartupLog で私たちは child_exit() ハンドラをこのように使いました:

sub child_exit {
my ($child_pool, $s) = @_;
say("process $$ now exits");
return Apache2::Const::OK;
}

The example handler logs the pid of the child process it's run in and returns.

この例のハンドラはそれが実行されている child プロセスの pid をログしてリターンします。
As you've seen in the example this handler is configured by adding to httpd.conf:

あなたが例示で見たとおりこのハンドラは httpd.conf に追加することで構成されます:

PerlChildExitHandler MyApache2::StartupLog::child_exit



Apache コマンドラインのコマンド : Apache Command-line Commands


Some notes on how Apache start/restart Apache commands affect mod_perl.

Apache の start/restart Apache コマンドがどのように mod_perl に影響するかのいつくかの注意。
META: not sure this is the best place for this section, but start some notes here.

META: これがこのセクションのためにベストな場所かはわかりませんが, ここでいくつかの注意をスタートしてください。
Apache re-parses httpd.conf at least once for each of the following commands (and will run any mod_perl code found in it).

Apache は次のコマンドごとに少なくとも 1 度 httpd.conf を再パースします (それとその中で見つかった mod_perl コードを実行します)。

  • httpd -k start
    No special issues here.

    ここには特に問題はありません。
    Apache start and immediately restarts itself.

    Apache はスタートして自身ですぐにリスタートします。

  • httpd -k restart
    This will abort any processed requests and restart the server.

    これは処理されたリクエストをすべて中止してサーバをリスタートします。
    All kind of problems could be encountered here, including segfaults and other kind of crashes. This is because when the SIGTERM signal is sent, things in process will be aborted.

    セグメンテーション違反 (# segfaults) とその他の類のクラッシュを含む, あらゆる種類の問題はここでエンカウントするはずです。これは SIGTERM シグナルが送信されたときに, 処理中のものが中止されるからです。
    Avoid using this method.

    この手法の使用はさけてください。
    Alternatively httpd -k restart can be executed kill -HUP HTTPD_PID.

    httpd -k restart のかわりに kill -HUP HTTPD_PID を実行できます。

  • httpd -k graceful
    No issues here. Apache starts and restarts itself just like with start, but it waits for the existing requests to finish before killing them.

    ここに問題はありません。Apache は start と同じくそれ自身でスタートとリスタートしますが, これは既存のリクエストをキルする前にそれらが終了するまで待ちます。
    Alternatively httpd -k graceful can be executed kill -USR1 HTTPD_PID.

    httpd -k graceful のかわりに kill -USR1 HTTPD_PID を実行できます。

  • httpd -k stop
    Similarly to httpd -k restart you may encounter all kind of issues here, due to the SIGTERM signal.

    httpd -k restart と同様に SIGTERM シグナルに起因して, あなたはここであらゆる種類の問題にエンカウントするかもしれません。




mod_perl のスタートアップ : mod_perl Startup


The following sections discuss the specifics of the mod_perl startup.

次のセクションは mod_perl スタートアップの詳細を論じます。


スタートしてすぐにリスタート : Start Immediately Restarts


As explained in the Server Life Cycle section, on start Apache normally runs the server configuration phase, followed by PerlOpenLogsHandler and PerlPostConfigHandler phases, then immediately restarts itself. Therefore everything running at the server startup is executed twice. During the restart, Perl is completely destroyed and started again.

Server Life Cycle セクションで説明したように, Apache のスタートでは普通サーバ構成フェーズを実行し, PerlOpenLogsHandler と PerlPostConfigHandler フェーズが続き, それからすぐにそれ自身でリスタートします。したがってサーバのスタートアップで走るものすべてが 2 回実行されます。リスタートの間, Perl は完全に破棄されて再びスタートされます。


perl はいつ実行をはじめるか : When Does perl Start To Run


If Apache is started as 'httpd -t' (equivalent to 'apachectl configtest') or as 'httpd -S', it will run only the configuration phase and exit. Depending on your configuration file, it may or may not start perl. See the details below.

Apache が 'httpd -t' ('apachectl configtest' と同等) としてまたは 'httpd -S' としてスタートされると, それは構成フェーズのみを実行して終了します。あなたの構成ファイルに応じて, それは perl をスタートしたりしなかったりします。詳細は以下を参照してください。
During the normal startup, mod_perl 2.0 postpones the startup of perl until after the configuration phase is over, to allow the usage of the PerlSwitches directive, which can't be used after Perl is started.

普通のスタートアップの間, mod_perl 2.0 は構成フェーズが終わるまで perl のスタートアップを後回しにして, Perl がスタートすると使えない PerlSwitches ディレクティブの使用をできるようにします
After the configuration phase is over, as the very first thing during the post_config phase, mod_perl starts perl and runs any registered PerlRequire and PerlModule entries.

構成フェーズが終わった後, post_config フェーズでの最初のものとして, mod_perl は perl をスタートして登録された PerlRequire と PerlModule エントリを実行します。
At the very end of the post_config phase any registrered PerlPostConfigRequire entries are run.

post_config フェーズの最後では登録された PerlPostConfigRequire エントリが実行されます。
When any of the following configuration directives is encountered (during the configuration phase) mod_perl 2.0 is forced to start as soon as they are encountered (as these options require a running perl):

次の構成ディレクティブのいずれかがエンカウントされたとき (構成フェーズ中) mod_perl 2.0 はそれらがエンカウントされるとすぐに強制的にスタートします (これらのオプションが実行中の perl を必要とするため):

Therefore if you want to trigger an early Perl startup, you could add an empty <Perl> section in httpd.conf:

したがってあなたが早期に Perl のスタートアップをトリガしたい場合, あなたは httpd.conf に空の <Perl> section を追加することができます:

<Perl>
# trigger an early Perl startup
</Perl>

right after loading the mod_perl module, if you are using DSO, or just before your mod_perl configuration section, if you're using a static mod_perl build. But most likely you want to use the PerlConfigRequire instead.

あなたが DSO を使っている場合は, mod_perl モジュールをロードした直後, またはあなたが静的な mod_perl のビルドを使っている場合は, あなたの mod_perl 構成セクションの直前です。けれども多分あなたはかわりに PerlConfigRequire を使うとよいはずです。


スタートアップファイル : Startup File


A startup file with Perl code to be executed at the server startup can be loaded using PerlPostConfigRequire. For example:

サーバのスタートアップで実行される Perl コードのスタートアップファイルは PerlPostConfigRequire を使ってロードできます。例えば:

PerlPostConfigRequire /home/httpd/perl/lib/startup.pl

It's used to adjust Perl modules search paths in @INC, pre-load commonly used modules, pre-compile constants, etc. Here is a typical startup.pl for mod_perl 2.0:

これは @INC の Perl モジュールのサーチパスの調整, 一般的に使われるモジュールのプレロード, 定数のプレコンパイル, etc に使われます。こちらは mod_perl 2.0 の典型的な startup.pl です:

#file:startup.pl
#---------------

use lib qw(/home/httpd/perl);

# enable if the mod_perl 1.0 compatibility is needed
# mod_perl 1.0 互換が必要とされるなら有効化
# use Apache2::compat ();

# preload all mp2 modules
# use ModPerl::MethodLookup;
# ModPerl::MethodLookup::preload_all_modules();

use ModPerl::Util (); #for CORE::GLOBAL::exit

use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::RequestUtil ();

use Apache2::ServerRec ();
use Apache2::ServerUtil ();
use Apache2::Connection ();
use Apache2::Log ();

use APR::Table ();

use ModPerl::Registry ();

use Apache2::Const -compile => ':common';
use APR::Const -compile => ':common';

1;

In this file @INC in adjusted to include non-standard directories with Perl modules:

このファイルで @INC は Perl モジュールで非標準ディレクトリを含むために調整されています:

use lib qw(/home/httpd/perl);

If you need to use the backwards compatibility layer load:

あなたが後方互換レイヤを使いたいならロードします:

use Apache2::compat ();

Next we preload the commonly used mod_perl 2.0 modules and precompile common constants.

次に私たちは一般的に使われる mod_perl 2.0 モジュールをプレロードして共通の定数をプレコンパイルしています。
Finally as usual the startup.pl file must be terminated with 1;.

最後にいつものとおり startup.pl ファイルは 1; で終わらせます。


リスタートの対処 : Dealing with Restarts


Ideally the code running at the server startup shouldn't be affected by the apache restart. If however this is not the case, you can use Apache2::ServerUtil::restart_count.

理想的にはサーバのスタートアップで走るコードは apache のリスタートに影響されるべきではありません。しかしこれがもしそうではないケースでは, あなたは Apache2::ServerUtil::restart_count を使えます。


メンテナ : Maintainers


Maintainer is the person(s) you should contact with updates, corrections and patches.
  • Stas Bekman [http://stason.org/]



作者 : Authors



Only the major authors are listed above. For contributors see the Changes file.


NEXT



次回は、「 Protocol Handlers 」を「 mod_perl 」公式サイト (https://perl.apache.org/index.html) より確認します。


参考情報は書籍「 続・初めての Perl 改訂版 」, 「 Effective Perl 第 2 版 」を中心に perldoc, Wikipedia および各 Web サイト。それと詳しい先輩。

目次 - Perl Index











































同じカテゴリー(Perl)の記事
 Perl mp2 翻訳 Web コンテンツ圧縮の FAQ (d228) (2023-10-11 23:49)
 Perl mp2 翻訳 既知のブラウザのバグの回避策をいくつか (d227) (2023-05-26 15:41)
 Perl mp2 翻訳 Perl と Apache でのキュートなトリック (d226) (2023-05-19 17:05)
 Perl mp2 翻訳 テンプレートシステムの選択 (d225) (2022-08-15 22:23)
 Perl mp2 翻訳 大規模 E コマースサイトの構築 (d224) (2022-06-15 20:43)
 Perl mp2 翻訳 チュートリアル (d223) (2022-06-15 20:42)
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。

Llama
リャマ
TI-DA
てぃーだブログ
プロフィール
セラ (perlackline)
セラ (perlackline)
QRコード
QRCODE
オーナーへメッセージ

PAGE TOP ▲