php 错误提示开启
<p><span style="font-size: 16px"><strong>开发环境项目,通常需要错误提示:<span style="color: rgba(255, 0, 0, 1)">php.ini文件,设置 display_errors = On </span></strong></span><br><span style="font-size: 16px"><strong>项目上线以后,当然不想把错误提示显示。</strong></span></p><p><span style="font-size: 16px"><strong>一般不直接修改php.ini文件,下面两行代码直接加入报错php文件:</strong></span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">ini_set</span>("display_errors", "<span style="color: rgba(255, 0, 255, 1)">On</span>");<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">打开错误提示</span>
<span style="color: rgba(0, 128, 128, 1)">ini_set</span>("error_reporting",<span style="color: rgba(255, 0, 255, 1)">E_ALL</span>);<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">显示所有错误</span></pre>
</div>
<p> </p>
<p><span style="font-size: 18px"><strong>error_reporting错误级别包括:</strong></span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 255, 1)">E_ALL</span> - 所有错误和警告(包括PHP 5.4.<span style="color: rgba(0, 0, 0, 1)">0中的E_STRICT)
</span><span style="color: rgba(255, 0, 255, 1)">E_ERROR</span> -<span style="color: rgba(0, 0, 0, 1)"> 致命的运行时错误
<span style="color: rgba(255, 0, 255, 1)">E_RECOVERABLE_ERROR</span></span>-<span style="color: rgba(0, 0, 0, 1)"> 几乎致命的运行时错误
</span><span style="color: rgba(255, 0, 255, 1)">E_WARNING</span> -<span style="color: rgba(0, 0, 0, 1)"> 运行时警告(非致命错误)
</span><span style="color: rgba(255, 0, 255, 1)">E_PARSE</span> -<span style="color: rgba(0, 0, 0, 1)"> 编译时解析错误
</span><span style="color: rgba(255, 0, 255, 1)">E_NOTICE</span> -<span style="color: rgba(0, 0, 0, 1)"> 运行时通知(这些通常是警告,从您的代码中的错误,但它可能是故意的(例如,使用未初始化的变量和赖于它自动初始化为一个事实空字符串)
</span><span style="color: rgba(255, 0, 255, 1)">E_STRICT</span> - 运行时通知,允许PHP建议更改您的代码将确保最佳的互操作性,<span style="color: rgba(0, 0, 0, 1)">并转发代码的兼容性
</span><span style="color: rgba(255, 0, 255, 1)">E_CORE_ERROR</span> -<span style="color: rgba(0, 0, 0, 1)"> PHP初始启动期间发生的致命错误
</span><span style="color: rgba(255, 0, 255, 1)">E_CORE_WARNING</span> - PHP期间发生的警告(非致命错误),<span style="color: rgba(0, 0, 0, 1)">初次启动
</span><span style="color: rgba(255, 0, 255, 1)">E_COMPILE_ERROR</span> -<span style="color: rgba(0, 0, 0, 1)"> 致命的编译时错误
</span><span style="color: rgba(255, 0, 255, 1)">E_COMPILE_WARNING</span> -<span style="color: rgba(0, 0, 0, 1)"> 编译时警告(非致命错误)
</span><span style="color: rgba(255, 0, 255, 1)">E_USER_ERROR</span> -<span style="color: rgba(0, 0, 0, 1)"> 用户生成的错误消息
</span><span style="color: rgba(255, 0, 255, 1)">E_USER_WARNING</span> -<span style="color: rgba(0, 0, 0, 1)"> 用户生成的警告消息
</span><span style="color: rgba(255, 0, 255, 1)">E_USER_NOTICE</span> -<span style="color: rgba(0, 0, 0, 1)"> 用户生成的通知消息
<span style="color: rgba(255, 0, 255, 1)">E_DEPRECATED </span></span>-<span style="color: rgba(0, 0, 0, 1)"> 警告代码在将来的PHP版本中不起作用
<span style="color: rgba(255, 0, 255, 1)">E_USER_DEPRECATED </span></span>- 用户生成的弃用警告</pre>
</div>
<p><strong><span style="font-size: 18px">error_reporting最常见的几种设置:</span></strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(255, 0, 255, 1)">E_ALL</span><span style="color: rgba(0, 0, 0, 1)"> (显示所有错误,警告和通知,包括编码标准。)
</span><span style="color: rgba(255, 0, 255, 1)">E_ALL</span> & ~<span style="color: rgba(255, 0, 255, 1)">E_NOTICE</span><span style="color: rgba(0, 0, 0, 1)">(显示所有错误,通知除外)
</span><span style="color: rgba(255, 0, 255, 1)">E_ALL</span> & ~<span style="color: rgba(255, 0, 255, 1)">E_NOTICE</span> & ~<span style="color: rgba(255, 0, 255, 1)">E_STRICT</span><span style="color: rgba(0, 0, 0, 1)">显示所有错误,通知和编码标准警告除外。)
</span><span style="color: rgba(255, 0, 255, 1)">E_COMPILE_ERROR</span>|<span style="color: rgba(255, 0, 255, 1)">E_RECOVERABLE_ERROR</span>|<span style="color: rgba(255, 0, 255, 1)">E_ERROR</span>|<span style="color: rgba(255, 0, 255, 1)">E_CORE_ERROR</span>(仅显示错误)</pre>
</div>
<p> </p>
<p><span style="font-size: 18px"><strong>nginx+php 开启PHP错误日志</strong></span></p>
<p><strong><span style="font-size: 18px">php-fpm.conf:</span></strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">catch_workers_output <span style="color: rgba(0, 0, 0, 1)">= yes</span></span> ;错误输出选项开启,如果没有添加</pre>
</div>
<p><span style="font-size: 18px"><strong>php.ini:</strong></span></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 255, 1)">error_reporting</span>=<span style="color: rgba(0, 0, 0, 1)"><strong>E_ALL</strong></span><span style="color: rgba(0, 0, 0, 1)"> ;显示所有错误
<span style="color: rgba(0, 0, 255, 1)">display_errors </span></span>=<span style="color: rgba(0, 0, 0, 1)"> Off </span> <span style="color: rgba(0, 0, 0, 1)"> ;关闭错误提示
<span style="color: rgba(0, 0, 255, 1)">log_errors </span></span>=<span style="color: rgba(0, 0, 0, 1)"> On ;错误日志开启
<span style="color: rgba(0, 0, 255, 1)">log_errors_max_len </span></span>= 1024<span style="color: rgba(0, 0, 0, 1)"> ;设置日志最大长度
</span><span style="color: rgba(0, 0, 255, 1)">error_log</span> = /usr/<span style="color: rgba(255, 0, 0, 1)">local</span>/error.<span style="color: rgba(0, 0, 0, 1)">log</span> ;错误日志文件位置</pre>
</div><br><br>
来源:https://www.cnblogs.com/cxx8181602/p/11090549.html
頁:
[1]