【问题标题】:I have php errors when display_errors is offdisplay_errors 关闭时出现 php 错误
【发布时间】:2018-12-29 12:33:40
【问题描述】:

我有几个 php 错误出现在页面上:Notice: Undefined index 我有/etc/php/5.6/fpm/php.inidisplay_errors = Off

当我将值设置为On 时,我发现页面上的错误更多。

我的 htaccess 文件是空的,vHost conf 是:

<VirtualHost *:80>
        ServerName website1.tld
        DocumentRoot /home/website1

        ErrorLog /var/log/sites/ website1_error_log
        CustomLog /var/log/sites/ website1_access_log combined

        DirectoryIndex index.php index.html index.htm index.php4 index.php5

        <Directory /home/website1>
                Options -Indexes +FollowSymLinks
                AllowOverride All
                Require all granted
        </Directory>
        <FilesMatch \.php$>
                SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
        </FilesMatch>
        RewriteEngine on
</VirtualHost>

谢谢

【问题讨论】:

  • 答案当然是修复错误而不是压制它们。
  • 那么请显示出现错误的代码。不要隐藏错误,解决它们!
  • 这是一个大型生产网站,我无法纠正数千个 php 错误。在旧服务器上,不显示错误
  • 你改过php版本了吗? “我无法纠正数以千计的 php 错误” - 你怎么知道网站是否按预期工作?
  • @Jeto - 诸如未能分配资源或无法连接到某些 API 等错误是真正的错误,应该记录和调查 - 我可以理解。但是Notice: Undefined index 消息是草率的编码和潜在的指标,表明代码的质量通常值得怀疑。

标签: php apache fpm


【解决方案1】:

您不必更改此 /etc/php/5.6/fpm/php.ini 中的任何内容。您可以将 error_reporting(0) 放在应用程序/文件的顶部。

<?php
// Turn off error reporting
error_reporting(0);

【讨论】:

  • 当我将 error_reporting(0) 添加到脚本时,会显示错误
  • 请附上错误页面的截图以及您放置error_reporting(0)的代码
  • 在任何情况下关闭 error_reporting 都是一个非常糟糕的主意。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
  • 2014-04-16
  • 2017-05-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多