简体   繁体   English

在没有php.ini的情况下设置display_errors = 0和log_errors = 1

[英]Setting display_errors=0 and log_errors=1 without php.ini

For reasons outside my control I am unable to set display_errors=0 and log_errors=1 in php.ini on my production server. 由于我无法控制的原因,我无法在生产服务器上的php.ini中设置display_errors = 0和log_errors = 1。 I know I can set error_reporting(0); 我知道我可以设置error_reporting(0); to completely suppress all error messages, but this impacts both the log errors and the displayed errors. 完全抑制所有错误消息,但这会影响日志错误和显示的错误。 I was hoping there would be an equivalent to setting display_errors=0 and log_errors=1 at runtime. 我希望在运行时设置display_errors = 0和log_errors = 1等效。 Is this possible? 这可能吗? Thanks. 谢谢。

Both are PHP_INI_ALL , so you can just use ini_set at runtime. 两者都是PHP_INI_ALL ,因此您可以在运行时使用ini_set

ini_set('display_errors', 0);
ini_set('log_errors', 1);

See http://php.net/manual/en/ini.list.php http://php.net/manual/en/ini.list.php

try this: 试试这个:

ini_set('display_errors', 0);
ini_set('log_errors', 1);

If you are using PHP as module and cannot use php.ini main directive nor overrided php.ini on the desired folder, and you won't to enable it on php file, yo can try to use .htaccess habilities. 如果您使用PHP作为模块并且不能使用php.ini主指令也不能覆盖所需文件夹上的php.ini,并且您不会在php文件上启用它,您可以尝试使用.htaccess habilities。

On the top of the folder containing your app, put an .htaccess file with: php_flag display_errors 0 在包含您的应用程序的文件夹的顶部,放置一个.htaccess文件: php_flag display_errors 0

Should apply only to the php output display not the logs. 应该只适用于php输出显示而不是日志。

Anyway, the solution provided about ini_set() will apply only to the pages who contain it. 无论如何,关于ini_set()提供的解决方案将仅适用于包含它的页面。 Note: If you have includes, the display_error value will work when parse it. 注意:如果包含,则display_error值在解析时将起作用。 But if you access it directly won't work. 但是如果你直接访问它将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM