rodrunner
rodrunner

Reputation: 1930

Check dynamically loaded PHP extensions from command line

I was checking the PHP manual to understand the different types of PHP extensions (PHP modules). There are Zend modules (mainly for PHP gurus), built-in modules and external modules.

Is there a way to tell from command line whether a PHP module has been loaded dynamically or whether it has built-in into the PHP binary?

I mean: with php -m I get all the loaded modules, but I would like to know which ones are built-in and which ones are external.

Upvotes: 27

Views: 61888

Answers (3)

Hillel Barak
Hillel Barak

Reputation: 89

1) Run

php -i

from the output locate the following parameters:

Loaded Configuration File - this will specify the location of the php.ini file being used by your php.

Scan this dir for additional .ini files - if this is not empty, some of the .ini files in this directory will dynamically load php extensions.

Additional .ini files parsed - .ini files loaded from the directory specified in the previous parameter.

If you are using Linux you could:

php -i | grep -e "Loaded Configuration File" -e "Scan this dir for additional .ini files" -e "Additional .ini files parsed"

2) Rename your php.ini file and rename the folder with additional .ini files.

3) Repeat step #1 and verify that Loaded Configuration File and Additional .ini files parsed both have a value of (none)

4) Run

php -m

You will now see a list containing only the extensions that are built-in to the php binary.

Upvotes: 8

mineroot
mineroot

Reputation: 1666

Just run this command on the command line:

php -m

or this for more information:

php -i

Hope this helps.

Upvotes: 75

Paul Dixon
Paul Dixon

Reputation: 300845

I'm not sure this is possible from regular PHP code, there may be some internal Zend calls you can make from an extension of your own. However, there might be a cheeky way of guessing, by checking if a loaded extension has a likely looking dynamic library available...

$extdir=ini_get('extension_dir');

$modules=get_loaded_extensions();
foreach($modules as $m){
    $lib=$extdir.'/'.$m.'.so';
    if (file_exists($lib)) {
        print "$m: dynamically loaded\n";
    } else {
        print "$m: statically loaded\n";
    }
}

That's not foolproof, but might be enough for you!

Upvotes: 3

Related Questions