php 如何配置 Codeigniter 报告所有错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7370391/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Codeigniter to report all errors?
提问by AppleGrew
I had a line - $autoload['libraries'] = array('database');
, in CI's autoload.php
. Because of this I was getting a blank page. When I removed the 'database'
, option then I started getting the output.
我有一条线 - $autoload['libraries'] = array('database');
,在 CI 的autoload.php
. 因此,我得到了一个空白页。当我删除'database'
, 选项时,我开始获取输出。
Now my question is not how to configure the database, but how to configure CI to speak its mind. When 'database'
was enabled all I got was a complete blank page. No error in php log, no error in Apache log, no error in CI log. In PHP I have set E_ALL
. In my CI config I have set log_threshold
to 4
, i.e. all messages should be logged. What more do I need to do?
现在我的问题不是如何配置数据库,而是如何配置CI来说出它的想法。当'database'
启用时,我得到的只是一个完整的空白页面。php日志没有错误,Apache日志没有错误,CI日志没有错误。在 PHP 中,我已经设置了E_ALL
. 在我的 CI 配置中,我已设置log_threshold
为4
,即应记录所有消息。我还需要做什么?
回答by davidethell
It depends on your version of CI. For < 2.x edit the top level index.php and adjust the error_reporting function to use E_ALL"
这取决于您的 CI 版本。对于 < 2.x 编辑顶级 index.php 并调整 error_reporting 函数以使用 E_ALL”
error_reporting(E_ALL);
For >= 2.x edit the top level index.php and make sure ENVIRONMENT is set as:
对于 >= 2.x 编辑顶级 index.php 并确保 ENVIRONMENT 设置为:
define('ENVIRONMENT', 'development');
which sets the error_reporting to E_ALL.
它将 error_reporting 设置为 E_ALL。
回答by Dennis Rasmussen
Create a .htaccess file in your webroot with the following content
使用以下内容在您的 webroot 中创建一个 .htaccess 文件
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value error_reporting -1
php_value log_errors_max_len 0
Hopefully that should enable your logs.
Make sure to set the values to offand reporting to 0on your production server :)
希望这应该可以启用您的日志。
确保在您的生产服务器上将这些值设置为关闭并报告为0:)
回答by faryal rida
Following environment settings would gonna force PHP to display errors as they occur:
以下环境设置将强制 PHP 在错误发生时显示:
- APPLICATION ENVIRONMENT define('ENVIRONMENT', 'development'); /*
ERROR REPORTING
if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'development': // Report all errors error_reporting(E_ALL);
// Display errors in output ini_set('display_errors', 1); break; case 'testing': case 'production': // Report all errors except E_NOTICE // This is the default value set in php.ini error_reporting(E_ALL ^ E_NOTICE); // Don't display errors (they can still be logged) ini_set('display_errors', 0); break; default: exit('The application environment is not set correctly.'); }
}
- 应用环境定义('环境','开发');/*
错误报告
if (defined('ENVIRONMENT')) { switch (ENVIRONMENT) { case 'development': // 报告所有错误 error_reporting(E_ALL);
// Display errors in output ini_set('display_errors', 1); break; case 'testing': case 'production': // Report all errors except E_NOTICE // This is the default value set in php.ini error_reporting(E_ALL ^ E_NOTICE); // Don't display errors (they can still be logged) ini_set('display_errors', 0); break; default: exit('The application environment is not set correctly.'); }
}
回答by AppleGrew
I am not sure what was the real reason but I had a PHP installation with left-over php.ini file. Later I installed the full WAMP stack with its own PHP. When I deleted the leftover php.ini file from the previous installation then it started working as it should. It seems the PHP binaries in the new installing was using using the left-over php.ini which was in totally different directory; maybe because that directory was in environment PATH.
我不确定真正的原因是什么,但我有一个带有剩余 php.ini 文件的 PHP 安装。后来我用自己的 PHP 安装了完整的 WAMP 堆栈。当我从以前的安装中删除剩余的 php.ini 文件时,它开始正常工作。新安装中的 PHP 二进制文件似乎使用的是完全不同目录中的剩余 php.ini;也许是因为该目录在环境 PATH 中。