“本地价值”和“主价值”的区别是什么?

当我显示 phpinfo();时,我看到两列: local valuemaster value。网络服务器什么时候选择 local value,什么时候选择 master value

71677 次浏览

"Master Value" (from php.ini) could be overridden with "Local Value" in httpd.conf, .htaccess or other Apache configuration with the php_value directive.

The first is the local value, and the second is the global value. The local value overrides the global value and is set within PHP, HTACCESS, etc., whereas the global value is set within php.ini. To answer your question, the first value is used.

master is either the value compiled into PHP, or set via a main php.ini directive. I.e., the value that's in effect when PHP fires up, before it executes any of your code.

local is the value that's currently in effect at the moment you call phpinfo(). This local value is the end result of any overrides that have taken place via ini_set() calls, php_value directives in httpd.conf/.htaccess, etc.

For example,

php.ini:     foo=bar
httpd.conf:  php_value foo baz
.htaccess:   php_value foo qux
ini_set:     ini_set('foo', 'kittens');
.user.ini    foo=bar   # this file works conditionally see https://stackoverflow.com/a/32193087/1818723

Given that, the master value is qux, and the local value is kittens.

The hosted website will check local values in .htaccess or .user.ini first. (These files are in your local website folder and also can say local level configuration files.)

Local values override Master values, so php will check the local values first.

The master value is set in php.ini (main PHP configuration file). Run the following commands in the terminal to find the correct path:

php -i | grep 'Configuration File'

or

php -i | grep php.ini

So even if we set master values in php.ini, we also need to check local values in .htaccess or .user.ini.

Here is explanation when .htaccess vs .user.ini works https://stackoverflow.com/a/32193087/1818723

local is website-or-user wide while master is system-wide configuration option.

would be easier and quicker to understand if it's named "global" instead of master

since the hidden .user.ini and .htaccess files are site-wide they contain local values along with the ini_set function to set options within the .php file

the PHPRC and PHP_INI_SCAN_DIR files would contain the master (global, system-wide) values

PHPRC: /etc/php.ini

PHP_INI_SCAN_DIR: /etc/php/*.ini