PHP 错误日志级别控制:htaccess vs php.ini vs 代码和虚拟主机

PHP Error log level control: htaccess vs php.ini vs code and virtualhost

我的 WAMP 本地服务器中有一个虚拟主机,我在其中设置了我的日志文件。

我想将我的 PHP 日志错误级别更改为仅警告和错误。

最好的方法应该是.htaccess,我试过这个解决方案:

How to disable notice and warning in PHP within .htaccess file?

没用(也试过其他的)。

最后转到 php.ini 文件,但是是不太灵活的选项。

1) 本级错误指令的优先级有哪些? (php.ini 对比 htaccess 对比代码) 我猜是那个顺序?

2) 为什么不能在 .htaccess 中工作? 我只是将它设置在 .htaccess 之上,但没有用。

我的建议是使用 httpd environment variable

这可以作为一个标志,通知您的 Web 应用程序有关环境的信息。假设您有一个白标产品,它可能很有用,例如设置应该与特定虚拟主机一起使用的配置。

<VirtualHost *:80>
  DocumentRoot "/srv/www/foo/public"
  ServerName foo.com

  <Directory /srv/www/foo/public>

    # production | development | staging
    SetEnv APPLICATION_ENV development
    ...

然后在您的 PHP 代码中,您可以像这样访问它:

<?php
define('APPLICATION_ENV_LOCAL', 'local');
define('APPLICATION_ENV_DEVELOPMENT', 'development');
define('APPLICATION_ENV_STAGING', 'staging');
define('APPLICATION_ENV_PRODUCTION', 'production');

$app_env = (getenv('APPLICATION_ENV')) ? getenv('APPLICATION_ENV') : false;
if (empty($app_env) || ! in_array($app_env, array(APPLICATION_ENV_LOCAL, APPLICATION_ENV_DEVELOPMENT, APPLICATION_ENV_STAGING, APPLICATION_ENV_PRODUCTION))) {
    throw new Exception("APPLICATION ENV IS NOT SPECIFIED OR IS INVALID.");
}

我要做的是根据环境包含完全独立的配置/INI 类型文件。这些可以确定错误报告行为,维护不同的数据库连接,以及任何其他依赖于应用程序环境的东西。

  1. Why is not working in .htaccess?

是否可以在 .htaccess 中设置 PHP 标志取决于 PHP 在服务器上的安装方式。 PHP 需要作为 Apache 模块安装。

但是,自 PHP 5.3 起,每个目录 PHP 配置文件以 .user.ini 文件的形式被支持(注意点前缀)。它们采用与 php.ini 文件相同的形式,但在用户空间代码中基于每个目录工作。

例如:

; All errors and warnings only
error_reporting=E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED
  1. Which are the priority of this level error instructions? (php.ini vs htaccess vs code) I guess that order?

是的,那个顺序(.htaccess.user.ini)。除了某些设置只能设置在链的更高位置,例如。在 php.ini.