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.

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

$strPhpInfo = ob_get_contents();

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

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


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