比较2 phpinfo设置 [英] comparing 2 phpinfo settings

查看:90
本文介绍了比较2 phpinfo设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想比较一下我在2台不同服务器上的设置.两者都是共享主机,因此我认为我没有足够的访问权限,只能通过phpinfo进行编程.因此,既然我有2个输出,我想比较它们而不需要手动检查它们.有自动化的方法吗?

I'd like to compare the settings I have on 2 different servers. Both are shared hosting so I don't think I have enough access to do it any other way but programmatically with phpinfo. So now that I have the 2 outputs, I'd like to compare them without examining them manually. Is there an automated way for this?

此外,作为附带说明,我认为是phpinfo是php.ini的输出.这是正确的吗?

Also, as a side but related note, I think phpinfo is the output of php.ini. Is this correct?

推荐答案

来自PHP手册,位于phpinfo():

From the PHP Manual on phpinfo():

输出有关PHP当前状态的大量信息.这包括有关PHP编译选项和扩展,PHP版本,服务器信息和环境(如果作为模块编译),PHP环境,OS版本信息,路径,配置选项的主值和本地值,HTTP标头和PHP的信息.执照.

Outputs a large amount of information about the current state of PHP. This includes information about PHP compilation options and extensions, the PHP version, server information and environment (if compiled as a module), the PHP environment, OS version information, paths, master and local values of configuration options, HTTP headers, and the PHP License.

phpinfo()的作用不只是打印出php.ini设置.

phpinfo() does more than just printing out php.ini settings.

如果要手动处理php.ini设置,则可能要签出 ini_get_all() 而不是phpinfo().这将返回所有配置值的数组.

If you want to process php.ini settings manually, you might want to check out ini_get_all() instead of phpinfo(). This returns an array of all configuration values.

您可以将ini_get_all()的输出从服务器A传输到服务器B(例如,通过使用 var_export() 创建PHP代码以创建数组,或者 serialize() ),然后使用 array_diff_assoc() 比较设置.

You could transfer the output of ini_get_all() from server A to server B (for example by using var_export() to create PHP code to create the array, or serialize()), then use array_diff_assoc() to compare the settings.

export.php :(服务器A)

<?php echo serialize(ini_get_all()); ?>

compare.php :(服务器B)

<?php
function ini_flatten($config) {
    $flat = array();
    foreach ($config as $key => $info) {
        $flat[$key] = $info['local_value'];
    }
    return $flat;
}

function ini_diff($config1, $config2) {
    return array_diff_assoc(ini_flatten($config1), ini_flatten($config2));
}

$config1 = ini_get_all();

$export_script = 'http://server-a.example.com/export.php';
$config2 = unserialize(file_get_contents($export_script));

$diff = ini_diff($config1, $config2);
?>
<pre><?php print_r($diff) ?></pre>

这篇关于比较2 phpinfo设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆