Symfony2のCommandでproductionモードで実行する方法
前にCommandを使ってバッチからメール送信する時の事を書きました。
これね id:amidaike:20130414
で、無事にメール送信できたのでいざ本番で試そうと思ったところ、
困った事にdebugモードで実行されてしまう。。なぜだ。。
という事でまたまた調べましょう。まんどくせぇ。。
たとえばCommandのconfigureを以下のように書いた場合、
protected function configure() { $this->setName('app:mail:sendmail')->setDescription('メール送信だよ〜ん'); }
と書いた場合、これをいざ実行しようとする時は、
app/console app:mail:sendmail
と書けば実行されるんですが、このままだとdebugモードで実行されてしまいます。
何なんだよ一体ということで、consoleのヘルプを眺めたらこんな風に書いていました。
$ app/console --help Usage: help [--xml] [command_name] Arguments: command The command to execute command_name The command name (default: "help") Options: --xml To output help as XML --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v) Increase verbosity of messages. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction (-n) Do not ask any interactive question. --shell (-s) Launch the shell. --process-isolation Launch commands from shell as a separate processes. --env (-e) The Environment name. (default: "dev") --no-debug Switches off debug mode. Help: The help command displays help for a given command: php app/console help list You can also output the help as XML by using the --xml option: php app/console help --xml list
どうやら--envと--no-debugを使うようです。
というわけで早速先ほどのコマンドを修正して実行してみましょう。
app/console --env=prod --no-debug app:mail:sendmail
と書いて実行すると、、、何という事でしょう。
無事にproductionモードで実行する事が出来ました。
う〜ん、またハマってしまった。。。
公式サイトのどこに書いているんだろうか。。おいらの探し方が悪いのか。。。。