php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66260 Provide phpinfo() alternative that returns array
Submitted: 2013-12-11 02:52 UTC Modified: 2015-05-29 08:54 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: preinheimer@php.net Assigned: kalle (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
 [2013-12-11 02:52 UTC] preinheimer@php.net
Description:
------------
There's several reasons to want an easily parsed phpinfo() output, chief amongst them to ensure that a series of servers have the same packages, and are configured in the same manner. There's a series of solutions[1] built on top of using the output from phpinfo(), then parsing it back into arrays. Clearly this is sub-optimal.

A userland alternative would be to run through the various functions like ini_get(), get_loaded_extensions(), etc. But not quite as pretty, I'm not sure if the same level of information is even exposed there (phpinfo() shows me master, and current, can I get that from ini_get())?



[1] like http://php.net/phpinfo#84259

Test script:
---------------
$config = phpinfo(-1, TRUE);
echo json_encode($config);


Expected result:
----------------
A beautiful json output of the PHP's server configuration. I'd then be able to use PHP's glorious array functions to easily compare it to another server's and find problems. 

Actual result:
--------------
Hrm, this seems like the kind of question I'd see on a test. phpinfo() will error because it's not expecting the second parameter, so I'll run with C) error. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-28 14:21 UTC] me at paulofreitas dot me
Yeah, it's PHP 5.6 days and it still a nightmare to get a single info from phpinfo() output. phpinfo() doc comments have a few tricks to do this, but it's far from ideal. A built-in function like phpinfo_array() which expose this data in a more meaningful way would be very welcome! :)
 [2015-05-29 08:54 UTC] kalle@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: kalle
 [2015-05-29 08:54 UTC] kalle@php.net
While this internally is not a trival task, it is just a little time consuming.

This is because the PHP_MINFO hook for each extension can choose to write their "style" for each block in the phpinfo() output. Personally I don't see this happening in 7.0, mainly due to extension structure changes it would require.

Sadly this needs to be done in userland PHP code for the next long time, I think its better to go for an RFC when the next major version is coming out for a richer discussion about this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 03:01:29 2024 UTC