dousi4900 2018-03-20 19:53
浏览 76
已采纳

有没有办法看到哪些php.ini值具有非默认设置?

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.

  • 写回答

1条回答 默认 最新

  • doudou3213 2018-03-20 20:51
    关注

    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("
    Defaults that are changed by or not present in ini file $path:
    ");
    print_r(array_diff_assoc($defaults, $ini));
    
    echo("
    Values set by $path which differ from or are not included in the defaults:
    ");
    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效