Search code examples
command-line-interfacephp-extension

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.


Solution

  • 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!