r/PHPhelp • u/thmsbrss • Dec 30 '25
Machine readable php -i output
Is there a CLI tool that outputs information similar to that from `php -i` in a machine-readable format such as JSON, YAML, or similar?
4
Upvotes
6
u/birdspider Dec 30 '25
probably have to do it yourself, something like:
3
u/HolyGonzo Dec 31 '25
Here's a simple php -i parser that dumps the output into JSON:
You call it like this (assuming you saved the script as "phpinfo2json.php")
Note that I explicitly stop parsing as soon as we reach the section listing out variables, but everything above that should be all the typical infrastructure stuff such as modules and so on.
1
u/thmsbrss Jan 01 '26 edited Jan 01 '26
Here it is /u/HolyGonzo
Supports only JSON at the moment, besides HTML and TEXT of course, since it's a simple wrapper to the phpinfo() function.
4
u/HolyGonzo Dec 31 '25
Out of curiosity, if the goal is to compare environments, why not just compare the php.ini files and the module and version output (php -m and php -v)?
If you truly need the phpinfo output, then I'll say that I tried to do something like this a while back and ran into two big problems:
There can also be minor differences, such as paths, basic environmental stuff like hostnames, or compiler flags.
So even when things had FUNCTIONALLY identical setups, the output still
It might be better to define the specific things you're looking to compare and then create a script that reads STDIN and parses those specific things and then outputs them in the desired format.
I can provide an example of what I mean in a little bit.
3
u/Ill_Store5106 Dec 31 '25
Search Packagist for "stechstudio/phpinfo". I think that might be what you're looking for.
-3
u/Timely-Tale4769 Dec 30 '25
First of all why is it necessary for you?