9

我需要一种方法来查找所有可用的 PHP 扩展,无论它们是否已加载。我查看了如何查看 PHP 加载的扩展? 但它只解释了如何找到加载的扩展。我也想要一种方法来找到卸载的扩展。

从 php.ini 知道 extension_dir 我做了一个ls /extension_dir/*.so返回 26 个条目的操作。当我尝试使用 时php -m,我得到了 57 个条目。这怎么可能?

我如何知道可以加载哪些 PHP 扩展?我不想知道哪些已加载但哪些是可加载的。

4

3 回答 3

4

请记住,某些扩展可能会静态构建到 PHP 中。您将在 php.ini 中看到这些作为扩展名列出,但您将无法禁用它们,并且在大多数情况下,您不会在 php.ini 或 .so / .DLL 文件中看到引用它们的 extension= 行。删除静态编译的扩展需要重新编译 PHP 本身,在大多数情况下,这几乎不需要,因为大多数静态编译的扩展往往包含很少需要删除的核心功能。

http://arr.gr/blog/2012/06/on-php-extensions/

感谢马泰奥·塔西纳里。

于 2012-08-28T11:12:29.233 回答
2

If you want the list of possibly loadable extensions, you should get the list of the files with an extension equal to the value of PHP_SHLIB_SUFFIX, and that are in the directory where PHP checks for PHP extensions (<install-dir>/lib/php/extensions/<debug-or-not>-<zts-or-not>-ZEND_MODULE_API_NO). If you want to avoid those extensions that are already loaded, you should pass the name of the extension (without file extension) to extension_loaded().

Keep in mind that a file with the right file extension could not be loaded from PHP as extension because the file doesn't have the right structure (for example because the file is corrupted), or because the PHP extension depends from files the extension doesn't find, or it is not able to load.

于 2012-08-28T13:49:04.627 回答
1

一种方法是检查“extension_dir”值:

phpinfo();

然后扫描目录以查看文件:

$exts = scandir("/usr/lib/php5/extension_dir/");
print_r($exts);
于 2012-09-22T20:47:11.480 回答