Useful Notes for phpinfo() & Capturing Output of phpinfo()

I recently needed to capture the output of phpinfo() for a to a log upon install. I’d been able to do this in the past but couldn’t quite remember how I managed it. This is where ob_start() and ob_flush() come into their own.

~

I recently needed to capture the output of phpinfo() for a to a log upon install. I’d been able to do this in the past but couldn’t quite remember how I managed it. This is where ob_start() and ob_flush() come into their own.

To get the contents of phpinfo(); into a variable, you can use the following:

ob_start();
phpinfo();
$strPhpInfo = ob_get_contents();
ob_clean();

The variable $strPhpInfo will now contain the output from phpinfo().

A side note, if you only want the variables section of phpinfo(), then use:

phpinfo(32);

and it’ll give you just that in the output. You can read more about the other values you can pass to phpinfo() at php.net/manual/en/function.phpinfo.php.