jigen studylog » クライアント版PHP でphp.iniを別に読み込む

jigen, Hirotomo Kunimatsu
Tokyo, Japan
mailto: microformat hcard
top

クライアント版PHP でphp.iniを別に読み込む

クライアント版PHP でphp.iniを別に読み込むphpを使ってコマンドラインの軽いスクリプトを組む時に、APCのようなキャッシュや、Browser Capabilities(browscap)とかでブラウザ判別をしてたりすると、コマンドラインを起動するのに色々Warningとかが表示されて面倒な時が多い。

とりあえずそれを別口のini(php.ini)を用意して、コマンドラインでphpを起動する時はその別の設定ファイルを読み込ませる事ができるそうなので、メモ。

例としては以下のような感じになる。要するにAPCだのbrowscapなどのコマンドラインなんかでは使わないようなライブラリは外した別のiniファイルを用意してそれを読み込みましょうという事。

#!/usr/bin/php -c /path/to/phpcli.ini
<?php
print "hoge";
exit();
?>

一行目のphpの場所を指定する部分にオプション「-c」を付けて設定ファイルを読み込んでいただきましょうという感じ。ちなみに、実行のたびに設定ファイルは読み直されるらしいです(ここではphpcli.ini)。

起動オプションは他にも色々あるらしいので、一応下に自分へのメモも含めてコピペしておきます。

Usage: php [options] [-f] <file> [--] [args...]
       php [options] -r <code> [--] [args...]
       php [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]
       php [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]
       php [options] -- [args...]
       php [options] -a

  -a               Run interactively
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse and execute <file>.
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -r <code>        Run PHP <code> without using script tags <?..?>
  -B <begin_code>  Run PHP <begin_code> before processing input lines
  -R <code>        Run PHP <code> for every input line
  -F <file>        Parse and execute <file> for every input line
  -E <end_code>    Run PHP <end_code> after processing all input lines
  -H               Hide any passed arguments from external tools.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.

  args...          Arguments passed to script. Use -- args when first argument
                   starts with - or script is read from stdin

  --ini            Show configuration file names

  --rf <name>      Show information about function <name>.
  --rc <name>      Show information about class <name>.
  --re <name>      Show information about extension <name>.
  --ri <name>      Show configuration for extension <name>.

スポンサードリンク

関連エントリー

よろしければ、以下リンクよりコメントをどうぞ。
2007/09/28 15:37:59200715:37
ネズミ「ここからメニューだすよ」
ネズミ「ごちそういっぱーい」
ネズミ「腹へったー」
ネズミ「働けー働けー♪」