Home > Article > Backend Development > How to display error message in php
How to set the php display error prompt: first open the "php.ini" file; then turn on the error prompt by setting "display_errors = On"; then add the content "ini_set("error_reporting",E_ALL);" to display All errors are OK.
Recommendation: "PHP Video Tutorial"
php error prompt is turned on
Development environment projects usually require error prompts: php.ini file, set display_errors = On
After the project is online, of course you do not want to display the error prompts.
Generally, the php.ini file is not modified directly. The following two lines of code are directly added to the error reporting php file:
ini_set("display_errors", "On");//打开错误提示 ini_set("error_reporting",E_ALL);//显示所有错误
error_reporting error levels include:
E_ALL - 所有错误和警告(包括PHP 5.4.0中的E_STRICT) E_ERROR - 致命的运行时错误 E_RECOVERABLE_ERROR - 几乎致命的运行时错误 E_WARNING - 运行时警告(非致命错误) E_PARSE - 编译时解析错误 E_NOTICE - 运行时通知(这些通常是警告,从您的代码中的错误,但它可能是故意的(例如,使用未初始化的变量和赖于它自动初始化为一个事实空字符串) E_STRICT - 运行时通知,允许PHP建议更改您的代码将确保最佳的互操作性,并转发代码的兼容性 E_CORE_ERROR - PHP初始启动期间发生的致命错误 E_CORE_WARNING - PHP期间发生的警告(非致命错误),初次启动 E_COMPILE_ERROR - 致命的编译时错误 E_COMPILE_WARNING - 编译时警告(非致命错误) E_USER_ERROR - 用户生成的错误消息 E_USER_WARNING - 用户生成的警告消息 E_USER_NOTICE - 用户生成的通知消息 E_DEPRECATED - 警告代码在将来的PHP版本中不起作用 E_USER_DEPRECATED - 用户生成的弃用警告
The most common settings for error_reporting:
E_ALL (显示所有错误,警告和通知,包括编码标准。) E_ALL & ~E_NOTICE (显示所有错误,通知除外) E_ALL & ~E_NOTICE & ~E_STRICT 显示所有错误,通知和编码标准警告除外。) E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR (仅显示错误)
nginx php Turn on PHP error log
php-fpm.conf: catch_workers_output = yes ;错误输出选项开启,如果没有添加
php.ini:
error_reporting = E_ALL ;显示所有错误 display_errors = Off ;关闭错误提示 log_errors = On ;错误日志开启 log_errors_max_len = 1024 ;设置日志最大长度 error_log = /usr/local/error.log ;错误日志文件位置
The above is the detailed content of How to display error message in php. For more information, please follow other related articles on the PHP Chinese website!