如何在命令行调用PHP时显示错误且不写入error_log文件?
命令行PHP开启终端错误显示并禁用错误日志写入
有两种可行的方法实现需求:
定向错误日志到空设备(推荐,不影响其他日志配置)
在命令行添加error_log配置项,将日志输出指向系统空设备,这样既不会生成本地error_log文件,又能在终端显示错误:- Linux/macOS环境:
php -d display_errors=on -d error_log=/dev/null filename.php - Windows环境:
php -d display_errors=on -d error_log=NUL filename.php
- Linux/macOS环境:
直接关闭错误日志功能
通过log_errors配置项关闭所有错误日志记录,同样能达到目的,但会禁用所有错误日志输出(包括系统级日志):php -d display_errors=on -d log_errors=off filename.php
内容的提问来源于stack exchange,提问作者Tristan
相关产品推荐
相关产品推荐

