By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,625 Members | 1,636 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,625 IT Pros & Developers. It's quick & easy.

PHP modules

P: n/a
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.

Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
sa****@gmail.com wrote:
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.


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

-Ivan Filippov
Jul 17 '05 #2

P: n/a
<sa****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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.


No such tool exists as far as I know.
Jul 17 '05 #3

P: n/a
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.

--enable-mods-shared=most

check out link for more details.

http://httpd.apache.org/docs-2.0/pro...configure.html

Jul 17 '05 #4

P: n/a
Would that only be for the Apache modules and not the PHP modules?

Jul 17 '05 #5

P: n/a
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?

Jul 17 '05 #6

P: n/a
thinking there wasn't any but it was worth a shot. Thank you.

Jul 17 '05 #7

P: n/a
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.
<?php
/*
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.

saidevATgmail.com
*/
//get all extensions that are loaded
$loadedExt = get_loaded_extensions();
$extFuns = array();
$fileslist = array();
$pathToCheck = "doc root"; //replace doc root with your document root
directory
$fileslist = getAllPHP($pathToCheck);
//there might be files with no read permission, avoiding getting
warning message
ini_set("display_errors",0);
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>";
}
unset($fileContent);
fclose($fileRead);
}
}
}
}
ini_set("display_errors",1);
//get all php files from given directory
//modified version of Jason Wong @
http://us3.php.net/manual/en/function.readdir.php 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 = "{$current_dir}/{$file}";
if (is_file($current_file)) {
if (eregi(".php",$file) || eregi(".inc",$file)) {
$file_list[] = "{$current_dir}/{$file}";
}
} elseif (is_dir($current_file)) {
$stack[] = $current_file;
}
}
}
}
}
return $file_list;
}

?>

Jul 17 '05 #8

P: n/a
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.

Jul 17 '05 #9

P: n/a
saidev wrote:
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?

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.

<?php

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='http://www.php.net/manual/en/function." .
str_replace("_", "-", $func) . ".php'>$func</a>\n";
}
print "</UL>\n";

}
echo "</UL>\n";

?>
J Wynia
Sokkit - web server toolkit for Windows
http://www.sokkit.net
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.