27

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.

3 Answers 3

75

Just run this command on the command line:

php -m

or this for more information:

php -i

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

How does this help distinguish between dynamically-loaded extensions and those built into the binary? As far as I can tell both kinds show up identically. Unless I'm missing something, this is totally irrelevant to the question asked - especially since the asker mentioned php -m in the question and explained why it doesn't give him the information he needs.
People read the subject, not the whole question, and find the answer that they are looking in the second answer, not the first one. To correct that, question's subject should be more specific that only dynamically loaded extensions are what he is interested in: "Check dynamically loaded PHP extensions from command line"…
8

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.

1 Comment

The command line php --ini may be an easier way of finding out step (1) in this list.
3

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!

1 Comment

But the script would need to check also if the .so library is included in the php.ini (if a line with "extension=$m.so" has ben added) ? Also, I was wondering if there's any information about this in phpinfo() output, but I could not see it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.