phpとxdebug

xdebugは便利だけど、勝手に省略されるのが玉に瑕

PHPのデバッグでxdebugを導入していているときに、配列などをvar_dumpした際に内容が長くなると、ブラウザで見た時に途中で切れて表示されてしまうことがあります。というか昨日からこれで結構困ってました。

これでは内容がきちんと確認できないので、省略させずに全て表示させる方法をやってみたので、メモ代わりに書いてみます。

php.iniの設定を変更してみる

参考にしたのは、xdebugの公式ドキュメント。
XDEBUG EXTENSION FOR PHP | DOCUMENTATION

xdebug.var_display_max_children
Type: integer, Default value: 128
Controls the amount of array children and object’s properties are shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.

To disable any limitation, use -1 as value.

This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.

xdebug.var_display_max_data
Type: integer, Default value: 512
Controls the maximum string length that is shown when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.

To disable any limitation, use -1 as value.

This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.

xdebug.var_display_max_depth
Type: integer, Default value: 3
Controls how many nested levels of array elements and object properties are when variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars or through Function Traces.

The maximum value you can select is 1023. You can also use -1 as value to select this maximum number.

This setting does not have any influence on the number of children that is send to the client through the Remote Debugging feature.

要はphp.iniの設定ファイルに下記の3行を追記すればいいみたいです。

xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1
xdebug.var_display_max_depth = -1

設定としては全て無制限に表示させるようになっています。

追記後、php.iniファイルを上書き保存して、httpdを再起動します。

# service httpd restart

無事、デバッグ内容が全て表示されました。よかったー。

【追記】上限を設定しないと大量のログが吐き出される

環境によっては上限を設定しないと、大量のエラーログが吐出されてしまいます。なので、なるべく上限を適宜調整しながら設定した方が良さそう。

ちなみに各設定の中身はこのようになっています。

; 表示する子要素の数
xdebug.var_display_max_children = -1
; 表示する要素の数
xdebug.var_display_max_data = -1
; 表示する階層の深さ
xdebug.var_display_max_depth = -1

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください