Pretty PHP Info: A Modern Replacement for `phpinfo()`
发布日期 经过 亚尼克·林·法特
Pretty PHP Info is a package by
Joseph Szobody
of Signature Tech Studio that replaces the default
phpinfo()
output with a modern, searchable UI — and adds a PHP API for querying your PHP configuration programmatically.
The simplest way to use it is the
prettyphpinfo()
drop-in function:
prettyphpinfo
();
That swaps out the default output for a dark-mode-ready page with instant search and click-to-copy values. You can pass the same
INFO_*
constants as
phpinfo()
to filter which sections are shown:
// Only show modules (useful for hiding environment variables)prettyphpinfo
(
INFO_MODULES
(英文):// Combine flagsprettyphpinfo
(
INFO_GENERAL
|
INFO_MODULES
(英文):
Querying PHP Configuration Programmatically
Beyond the UI, the package gives you an API to inspect your PHP configuration in code. Capture the output with
Info::capture()
and then query it:
使用
STS\Phpinfo\Info
;$info
=
信息
::
捕获
();$info
->
版本
();
// "8.4.19"$info
->
hasModule
(
'mysqli'
(英文):
// 真的$info
->
配置
(
'post_max_size'
(英文):
// "32M" (local/effective value)$info
->
配置
(
'post_max_size'
,
'master'
(英文):
// "2M" (php.ini default)$info
->
os
();
// "Linux"$info
->
主机名
();
// "my-server"
One notable capability is fetching both the local (effective) value and the master (php.ini default) for any directive — something
ini_get()
alone can't do.
Why Not Just Use
ini_get()
?
PHP scatters its configuration across several functions —
ini_get()
,
extension_loaded()
,
get_loaded_extensions()
,
phpversion()
— and each one only tells you one specific thing. None of them let you discover what's available, iterate over all configuration, or see phpinfo()-only data like compile options, stream wrappers, and registered filters.
phpinfo()
is the only function that gives you everything in one place, but it outputs raw HTML or plain text with no API to work with. This package parses that output and exposes it through a consistent interface.
Iterating Over Configuration
You can also walk the full configuration structure. Modules, groups, and configs are returned as iterable
Items
collections with
filter()
,
map()
,
first()
,
each()
, 和
count()
:
foreach
($info
->
模块
()
作为
$module) {
回声
'<h2>'
。
$module
->
姓名
()
。
'</h2>'
;
foreach
($module
->
配置
()
作为
$config) {
回声
$配置
->
姓名
()
。
':'
。
$配置
->
价值
();
如果
($config
->
hasMasterValue
()){
回声
' (master: '
。
$配置
->
masterValue
()
。
')'
;}}}
The data structure mirrors how
phpinfo()
organizes things:
PhpInfo
→
modules()
→
groups()
→
configs()
. You can also flatten and access configs directly from any level.
You can load previously saved
phpinfo()
output as well:
$info
=
信息
::
fromHtml
($savedHtmlOutput);$info
=
信息
::
来自文本
($savedTextOutput);$info
=
信息
::
detect
($savedOutput);
// auto-detects format
安装
Requires PHP 8.3+ and
ext-dom
。
作曲家
要求
stechstudio/phpinfo
You can view the source code for the package on GitHub or learn more on the official website at prettyphpinfo.com 。






