PHP modules

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

A quick question, I'm about to recompile PHP, last time I compiled it
with alot of modules, thinking that this time I should not need that
many.  Is there any tool(s) that could run under the htdocs and scan
the PHP and tell me what modules actually being use?  Thanks.

Re: PHP modules wrote:
Quoted text here. Click to load it

Make a php page that uses this function: phpinfo()
So, something like this:
That will give you useful info about the current PHP installation AND
will give you a list of installed mods.

-Ivan Filippov

Re: PHP modules

Thanks, but I'm trying to elimate modules that don't need anymore, the
phpinfo() only provide me what is installed but not what is used.  Any
other thoughts?

Re: PHP modules

saidev wrote:
Quoted text here. Click to load it
Here's a bit of code that will list the functions available in your
current installation. If, instead of printing them out in an unordered
list, you used the $f array in the script as the basis for digging
through your site code, looking for instances of those functions, you'd
be pretty close to what you want. I'd go through, and if an instance is
found, cull it from the array. When you've looped through all of your
code, the remaining functions have never been invoked in your code and
you'll have a list of functions you don't use, which should pretty
quickly point out which extensions you don't use.


<h2>Get Available Functions</h2>
Below is a list of all of the functions available to your PHP scripts.
After enabling other extensions, their functions will appear here.
Clicking on a function name will bring up the PHP manual page for that


function usort_cmp($a, $b) {
return (strtolower($a) == strtolower($b)) ? 0 : (strtolower($a) >
strtolower($b)) ? 1 : -1;

echo "<UL>\n";
$le = get_loaded_extensions();
usort($le, "usort_cmp");
foreach($le as $module) {
print "<LI>$module\n";
print "<UL>\n";

$f = get_extension_funcs($module);
usort($f, "usort_cmp");

foreach($f as $func) {
print "<LI><a href=' ." .
str_replace("_", "-", $func) . ".php'>$func</a>\n";
print "</UL>\n";

echo "</UL>\n";


J Wynia
Sokkit - web server toolkit for Windows

Re: PHP modules

Quoted text here. Click to load it

No such tool exists as far as I know.

Re: PHP modules

thinking there wasn't any but it was worth a shot.  Thank you.

Re: PHP modules

Since there isn't any program written to check for module usage of your
current website, I decided to write on myself, hope this might be
helpful to others.
This script is to use to see if any of the web pages is using
the loaded modules, it will parse all php files of a given't path to
search every page
for those functions that might be associated with the modules.
This is useful if you have many modules compile in the current version
of PHP but
wanting to upgrade with less modules and not knowing which module
functions the programmer
might have used.
//get all extensions that are loaded
$loadedExt = get_loaded_extensions();
$extFuns = array();
$fileslist = array();
$pathToCheck = "doc root";  //replace doc root with your document root
$fileslist = getAllPHP($pathToCheck);
//there might be files with no read permission, avoiding getting
warning message
foreach ($loadedExt as $ext) {
    //skipping some standard modules
    if (strtolower($ext) != "standard" && strtolower($ext) != "sybase_ct"
        strtolower($ext) != "session"  && strtolower($ext) != "mysql" &&
        strtolower($ext) != "gettext") {
        echo "Scanning Module <strong>$ext</strong><BR>";
        //get all functions for current scanning modules
        $extFuns = get_extension_funcs($ext);
        //loop thru each module functions
        foreach ($extFuns as $function) {
            for ($i = 0 ; $i < count($fileslist); $i++) {
                $fileRead = fopen($fileslist[$i],"r");
                $fileContent = fread($fileRead,filesize($fileslist[$i]));
                if (ereg($function,$fileContent)) {
                    echo "<strong>$function</strong> used in ".$fileslist[$i]."<BR>";
//get all php files from given directory
//modified version of Jason Wong @ example
function getAllPHP($dir) {
   $file_list = '';
   $stack[] = $dir;
   while ($stack) {
       $current_dir = array_pop($stack);
       if ($dh = opendir($current_dir)) {
           while (($file = readdir($dh)) !== false) {
               if ($file !== '.' AND $file !== '..') {
                   $current_file = "/";
                   if (is_file($current_file)) {
                        if (eregi(".php",$file) || eregi(".inc",$file)) {
                            $file_list[] = "/";
                   } elseif (is_dir($current_file)) {
                       $stack[] = $current_file;
   return $file_list;


Re: PHP modules

Yes, Sorry my example was only for apache modules. For php you can type
#php -m at a shell prompt to get a list of modules.

Good job on the code. Looks pretty useful for people who don't have a
predefined set of code and no that they aren't going to need any other
modules in the future. I'm sure people will get use out of that if they
want to trim down on the number of modules they have installed.

Just to be devils advocate here. I am wondering if installing a bunch
of extraneous modules will slow down the performance of PHP? It seems
like if you are doing development work you would want to enable most of
them in case you run into a problem that might require ldap or GD.

If you are administering a production box and the php code isn't going
to be changing any time soon, I think this code will come in handy.

Re: PHP modules

You could run the following command and see what modules you have
installed then look up the description of each and decide if you want
to enable them again.

#./httpd -l

When you are ./configure the command to enable alot of modules is.


check out  link for more details.

Re: PHP modules

Would that only be for the Apache modules and not the PHP modules?

Site Timeline