简体   繁体   English

如何查看 PHP 加载的扩展?

[英]How do I see the extensions loaded by PHP?

It's got to be somewhere in the phpinfo() dump, but I just don't know where.它必须在 phpinfo() 转储中的某个地方,但我只是不知道在哪里。 Is it supposed to be under the "Additional Modules" section?它应该在“附加模块”部分下吗? Somewhere else?别的地方? I'm trying to figure out why some extensions don't appear to be loaded, but I don't even know where I should be looking.我试图弄清楚为什么某些扩展似乎没有被加载,但我什至不知道我应该在哪里寻找。

Running跑步

php -m
will give you all the modules, and 会给你所有的模块,和
php -i php -i
will give you a lot more detailed information on what the current configuration. 将为您提供有关当前配置的更多详细信息。

Run command.运行命令。 You will get installed extentions:您将获得已安装的扩展:

php -r "print_r(get_loaded_extensions());"

Or run this command to get all module install and uninstall with version或运行此命令以获取所有模块的安装和卸载版本

dpkg -l | grep php5

You want to run:你想运行:

 php -m 

on the command line,在命令行上,

or if you have access to the server configuration file open或者如果您有权访问打开的服务器配置文件

/etc/php5/apache2/php.ini

and look at all the the extensions,看看所有的扩展名,

you can even enable or disable them by switching between On and Off like this您甚至可以通过像这样在 On 和 Off 之间切换来启用或禁用它们

<Extension_name> = <[On | Off]>

使用get_loaded_extensions() PHP 函数

  <?php 
      echo "<pre>";
      print_r(get_loaded_extensions());
      echo "<pre/>";
 ?>

如果您想测试是否加载了特定扩展,您还可以使用extension_loaded函数,请参阅此处的文档

php -r "var_dump(extension_loaded('json'));"

get_loaded_extensions() output the extensions list. get_loaded_extensions()输出扩展列表。

phpinfo(INFO_MODULES); output the extensions and their details.输出扩展名及其详细信息。

Are you looking for a particular extension?您在寻找特定的扩展名吗? In your phpinfo();在你的phpinfo(); , just hit Ctrl + F in your web browser, type in the first 3-4 letters of the extension you're looking for, and it should show you whether or not its loaded. ,只需在 Web 浏览器中按 Ctrl + F ,输入您要查找的扩展程序的前 3-4 个字母,它就会显示它是否已加载。

Usually in phpinfo() it doesn't show you all the loaded extensions in one location, it has got a separate section for each loaded extension where it shows all of its variables, file paths, etc, so if there is no section for your extension name it probably means it isn't loaded.通常在phpinfo()它不会在一个位置显示所有加载的扩展名,它为每个加载的扩展名都有一个单独的部分,其中显示了它的所有变量、文件路径等,因此如果您没有任何部分扩展名可能意味着它没有被加载。

Alternatively you can open your php.ini file and use the Ctrl + F method to find your extension, and see if its been commented out (usually by a semicolon near the start of the line).或者,您可以打开 php.ini 文件并使用Ctrl + F方法找到您的扩展名,并查看它是否已被注释掉(通常在行首附近用分号)。

You asked where do you see loaded extensions in phpinfo() output.你问你在哪里看到 phpinfo() 输出中加载的扩展。

Answer:回答:

They are listed towards the bottom as separate sections/tables and ONLY if they are loaded.它们作为单独的部分/表格列在底部,并且当它们被加载时。 Here is an example of extension Curl loaded.这是加载扩展卷曲的示例。

在此处输入图片说明 ... ...

... ... 在此处输入图片说明

I installed it on Linux Debian with我将它安装在 Linux Debian 上

sudo apt-get install php7.4-curl

You can see all extensions install by PHP by this您可以通过此查看 PHP 安装的所有扩展

-Debian/Ubuntu -Debian/Ubuntu

dpkg --get-selections | grep -i php

-RHEL/CentOS -RHEL/CentOS

yum list installed | grep -i php

-Fedora 22+ -Fedora 22+

dnf list installed | grep -i php

I was having the same issue, I needed to know what modules were installed and their version.我遇到了同样的问题,我需要知道安装了哪些模块及其版本。 For now, my solution is to have PHP tell me from the command line.目前,我的解决方案是让 PHP 从命令行告诉我。 Note, "Core" is PHP.注意,“核心”是 PHP。

php -r '$all = get_loaded_extensions(); foreach($all as $i) { $ext = new ReflectionExtension($i); $ver = $ext->getVersion(); echo "$i - $ver" . PHP_EOL;}'

Output: Output:

Core - 7.4.30
date - 7.4.30
libxml - 7.4.30
...
mcrypt - 1.0.5
bcmath - 7.4.30
bz2 - 7.4.30
...
xml - 7.4.30
xmlwriter - 7.4.30
xsl - 7.4.30
zip - 1.15.6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM