获取 PHP 版本和配置信息的 PHP 程序


2022年2月8日, Learn eTutorial
4932

为了更好地理解这个示例,我们始终建议您学习以下列出的 PHP 编程 的基础主题

PHP (PHP: Hypertext Preprocessor 的递归首字母缩写) 是一种广泛使用的开源通用脚本语言,尤其适合 Web 开发,并且可以嵌入到 HTML 中。

如何获取 PHP 版本和配置信息?

下面提到的程序是获取 PHP 当前状态的基本程序。为此,我们使用名为 `phpinfo()` 的内置函数。

phpinfo() -  输出有关 PHP 当前状态的信息,其中包括 PHP 编译选项和扩展、PHP 版本、服务器信息和环境、PHP 环境、操作系统版本信息路径、配置选项的主值和本地值、HTTP 头以及 PHP 许可证。

由于每个系统的设置都不同,`phpinfo()` 通常用于检查给定系统的配置设置和可用预定义变量。

`phpinfo()` 也是一个有价值的调试工具,因为它包含了所有 EGPCS (环境、GET、POST、Cookie、Server) 数据。

算法

步骤 1:使用 phpinfo() 显示版本和配置详细信息。

PHP 源代码

                                          <?php
phpinfo();
?>
                                      

输出

phpinfo() PHP Versi> 8.0.9

System => Linux 1ce19136f4d9 5.8.0-1041-aws #43~20.04.1-Ubuntu SMP Thu Jul 15 11:07:29 UTC 2021 x86_64
Build Date => Jul 30 2021 13:03:39
Build System => Linux
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/8.0/cli
Loaded Configuration File => /etc/php/8.0/cli/php.ini
Scan this dir for additional .ini files => /etc/php/8.0/cli/conf.d
Additional .ini files parsed => /etc/php/8.0/cli/conf.d/10-mysqlnd.ini,
/etc/php/8.0/cli/conf.d/10-opcache.ini,
/etc/php/8.0/cli/conf.d/10-pdo.ini,
/etc/php/8.0/cli/conf.d/15-xml.ini,
/etc/php/8.0/cli/conf.d/20-bz2.ini,
/etc/php/8.0/cli/conf.d/20-calendar.ini,
/etc/php/8.0/cli/conf.d/20-ctype.ini,
/etc/php/8.0/cli/conf.d/20-curl.ini,
/etc/php/8.0/cli/conf.d/20-dom.ini,
............................................................

PHP License
This program is free software; you can redistribute it and/or modify
it under the terms of the PHP License as published by the PHP Group
and included in the distribution in the file:  LICENSE

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you did not receive a copy of the PHP license, or have any
questions about PHP licensing, please contact [email protected].