前提
- PHP7.2
- php-fpm
- nginx
課題
PHPのエラーログを見ていたら、stacktraceが途中で途切れた。
PHP Fatal error: Uncaught Error: Call to a member function func() on array in /path/to/file.php:693
Stack trace:
# 0 /path/to/file.php(421): file->func('XXX')
# 1 /path/to/file.php(106): file->func(4)
# 2 /path/to/file.php(507): file->func()
# 3 /path/to/file.php(1337): file->func()
# 4 /path/to/file.php(1341): file->func(1)
# 5 /path/to/file.php(326): file->func(1)
# 6 /path/to/file.php(341): file->func('151', 1, Array)
# 7 /path/to/file.php(184): file::func('151', in /path/to/file.php on line 693
解決策
1.php.iniにある"log_errors_max_len"の値を書き換える
PHPのstacktraceの制限の設定はphp.iniファイルの中で、以下のように定義されている。
(略)
; Set maximum length of log_errors. In error_log information about the source is
; added. The default is 1024 and 0 allows to not apply any maximum length at all.
; http://php.net/log-errors-max-len
log_errors_max_len = 1024
(略)
ここを以下のように修正して保存すると制限が解除される。
log_errors_max_len = 0
2.php-fpmを再起動
上記のままだと反映されないので、php-fpmを再起動。
sudo systemctl restart php-fpm
これで設定が反映されて解決。
補足
php.iniファイルの場所がわからない人は、$ php --ini
を実行してみるといい。
$ php --ini
Configuration File (php.ini) Path: /home/user/.anyenv/envs/phpenv/versions/7.2.1/etc
Loaded Configuration File: /home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/php.ini
Scan for additional .ini files in: /home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/conf.d
Additional .ini files parsed: /home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/conf.d/apcu.ini,
/home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/conf.d/memcached.ini,
/home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/conf.d/phpredis.ini,
/home/user/.anyenv/envs/phpenv/versions/7.2.1/etc/conf.d/xdebug.ini
こんな感じで出てくるので、Loaded Configuration File を見ればOK