Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparing 2 phpinfo settings

Tags:

php

settings

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?

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

like image 620
Chris Avatar asked Oct 26 '09 08:10

Chris


People also ask

What is Phpinfo () function?

Because every system is setup differently, phpinfo() is commonly used to check configuration settings and for available predefined variables on a given system. phpinfo() is also a valuable debugging tool as it contains all EGPCS (Environment, GET, POST, Cookie, Server) data.

How do I view Phpinfo page?

Use your browser to go to http://example.com/info.php, where example.com represents your web site's domain name. The page displays a large amount of information about the PHP installation. For security reasons, you should disable any calls to the phpinfo() function when web site development and testing is complete.

How do I use Phpinfo in Wordpress?

Go to your website's admin panel. Select Plugins > Add New. search for phpinfo() WP by Imran Hossain Sagor. Click Install Now button. Then simply click Active.

How do I find Phpinfo on Windows?

Check PHP Version by Running PHP Codephp echo 'PHP version: ' . phpversion(); Create the file using a text editor like gedit or Notepad, and upload it to your website's document root directory. Note: While phpinfo() is useful for debugging, the page features sensitive information about your system.


2 Answers

From the PHP Manual on phpinfo():

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() does more than just printing out php.ini settings.

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.

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: (Server A)

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

compare.php: (Server 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>
like image 67
Ferdinand Beyer Avatar answered Oct 24 '22 00:10

Ferdinand Beyer


Comparing two php.ini files easily using a parse_ini_file function

Example code snippet

$firstIni  = parse_ini_file('/etc/php5/apache2/php.ini');
$secondIni  = parse_ini_file('/etc/php5/apache2/php.ini.save');
$firstIniDiff = array_diff($firstIni, $secondIni);
$secondIniDiff = array_diff($secondIni, $firstIni);

if (count($firstIniDiff) > 0) {
    echo '<h1>php.ini  changes</h1>';
    echo '<ol>';
    foreach ($firstIniDiff as $key => $val) {
        echo '<li> php.ini'.$key.': '.$val.' ----> php.ini.save :'.@$secondIniDiff[$key].'</li> ';
    }

    echo '</ol>';
}

if (count($secondIniDiff) > 0) {
     echo '<h1>php.ini.save  changes</h1>';
    echo '<ol>';
    foreach ($secondIniDiff as $key => $val) {
        echo '<li> php.ini'.$key.': '.$val.' ----> php.ini.save :'.@$firstIniDiff[$key].'</li> ';
    }

    echo '</ol>';
} 

Output

enter image description here

like image 45
Raja Rama Mohan Thavalam Avatar answered Oct 23 '22 23:10

Raja Rama Mohan Thavalam