问题描述
我想比较一下我在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()
:
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设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!