7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHPをコマンドラインから呼び出した時にエラーメッセージがダブるときの対処法

7
Last updated at Posted at 2015-09-10

問題

スクリーンショット 2015-09-10 23.41.19.png

同じこと2回言うな!

原因

ここによると…

  • log_errorsSTDERR に吐く。
  • display_errorsSTDOUT に吐く。

ということらしいです。なのでどっちかに限定しようという話です。

対処法

サーバモジュールとCLIモジュールで読み込むphp.iniが異なるとき

それぞれお好みで設定してください。

サーバモジュールとCLIモジュールで読み込むphp.iniが同じとき

auto_prepend_file ディレクティブで指定された、自動的に読み込まれるファイルに

サーバログにエラーを残したい場合
<?php
ini_set('log_errors', true);
ini_set('display_errors', PHP_SAPI !== 'cli');
サーバログにエラーを残す必要がない場合
<?php
ini_set('log_errors', PHP_SAPI === 'cli');
ini_set('display_errors', PHP_SAPI !== 'cli');

と書いておくと幸せになれるかもしれません。もちろんプロジェクトごとにこの記述を行っても構いません。

スクリーンショット 2015-09-10 23.50.29.png

気になる時だけこんな感じで -d オプションとして渡すのもありです。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?