Locate available (not loaded) PHP extensions
Asked Answered
D

3

9

I need a way to find all the available PHP extensions whether they are loaded or not. I looked at How do I see the extensions loaded by PHP? but it only explains how to find loaded extensions. I want a way to find unloaded extensions also.

Knowing the extension_dir from php.ini I did a ls /extension_dir/*.so which returned 26 entries. When I tried with php -m, I got 57 entries. How is it possible?

How do I know which PHP extensions are available to be loaded? I don't want to know which are loaded but which are loadable.

Discontinuous answered 28/8, 2012 at 10:41 Comment(3)
Some extensions are built-in with no external file.Synapse
Just putting the extension libraries in a directory doesn't necessarily mean they are loaded by php. see docs.php.net/manual/en/ini.core.php#ini.extensionOkwu
@matteo Tassinari , how ? is it defined at compile time or is it part of php itself ?Discontinuous
F
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.

Flirtation answered 28/8, 2012 at 13:49 Comment(0)
D
4

Keep in mind that some extensions may be build statically into PHP. You will see these listed as extensions in php.ini but you will not be able to disable them, and in most cases you will not see an extension= line referring to them in php.ini or an .so / .DLL files. Removing statically compiled extensions requires recompiling PHP itself, and in most cases this is hardly needed as most statically compiled extensions tend to include core functionality which rarely needs to be removed.

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

Thanks goes to Matteo Tassinari.

Discontinuous answered 28/8, 2012 at 11:12 Comment(4)
In which way does this answer the question being asked?Flirtation
Aren't statically build extensions already enabled? If the question is about extensions still to be loaded, then that excludes statically linked extensions.Flirtation
@kiamlaluno I am also confused. It's unclear to me if he's asking what I thought, or what GEOCHET thought.Bludgeon
@kiamlaluno , knowing that get_loaded_extensions() would not answer my needs helped me to find out how to list available extensions by listing the extension_dirDiscontinuous
F
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.

Flirtation answered 28/8, 2012 at 13:49 Comment(0)
S
1

One way is to check the 'extension_dir' value:

phpinfo();

Then scan the directory to see the files:

$exts = scandir("/usr/lib/php5/extension_dir/");
print_r($exts);
Slapup answered 22/9, 2012 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.