I've had to do some archeology on an old PHP 5 server. I've been digging around in the ini files and it occurred to me that it would be very convenient to check which settings have non-default values. I've discovered php --ini
and php -r 'php_info();'
and other variants, as well as the ini_get_all()
function, which can show the value set in the php ini files and any overridden value (e.g. from .htaccess
or ini_set
).
The php.net documentation describes a default setting for every ini directive. Is there a way to access these defaults from inside PHP code? That way I could do some simple array manipulations on the return value of ini_get_all
and pick out which ones have non-default values.
I was looking at ini_restore
and the example given reads as though it only restores to the startup value, i.e. the value configured in the ini files, not the php default value.
Additionally, you could rename your current ini file to something other than php.ini and restart PHP so that ini_get_all will give you the values which are baked into the core and use parse_ini_file() on your renamed file. – MonkeyZeus
This worked a charm! Before starting, I had a linked conf.d
and I had overridden the cli/php.ini
file to point to the apache2/php.ini
file so that my php cli invocations would use the web server configs. The cli/php.ini
file had been renamed .old
, like so:
$ ls -l /etc/php5/cli/
total 68
lrwxrwxrwx 1 root root 9 Apr 24 2013 conf.d -> ../conf.d
lrwxrwxrwx 1 root root 25 Mar 13 05:04 php.ini -> /etc/php5/apache2/php.ini
-rw-r--r-- 1 root root 67629 Mar 4 2013 php.ini.old
I took the web server out of our load balancer pool and made some modifications.
$ rm /etc/php5/cli/conf.d /etc/php5/cli/php.ini
$ php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: (none)
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: (none)
I then added a file called check_config.php
with these contents:
echo("\nDefaults that are changed by or not present in ini file $path:\n");
print_r(array_diff_assoc($defaults, $ini));
echo("\nValues set by $path which differ from or are not included in the defaults:\n");
print_r(array_diff_assoc($ini, $defaults));
And got some delicious output.
$ /usr/bin/php /etc/php5/cli/check_config.php
Defaults that are changed by or not present in ini file /etc/php5/apache2/php.ini:
Array
(
[allow_call_time_pass_reference] => 1
[allow_url_include] => 0
//...snip
)
Values set by /etc/php5/apache2/php.ini which differ from or are not included in the defaults:
Array
(
[engine] => 1
[asp_tags] =>
//...snip
)
This did what I wanted, but it has a lot of red herrings - a lot of directives have a default value but are not included in the ini file and similarly a lot of module specific directives that are not in the values returned by ini_get_all()
. I suppose I could improve this a bit by further finagling the config setups to enable more modules which should get their directives included in the list, but there are rather a lot of modules, so I think I'm good for now.