├── README ├── app.xml ├── php_unused_extensions_scanner.php └── unused_extensions_scanner.class.php /README: -------------------------------------------------------------------------------- 1 | Command line utilite for searching loaded, but unused php extenstion in files of indicated directory. 2 | 3 | This can be useful if you want to speed up your scripts. 4 | To do this, disable unused extensions in the configuration file of PHP. 5 | Some extensions may not be called out of the code but they may perfom service functions (xDebug, eAccelerator, APC, etc) 6 | Check the list of extensions before switching off 7 | 8 | Caution: The author does not guarantee 100% accuracy of the scanner work 9 | Make sure your applications work after you disable extensions. 10 | 11 | What extension is used, can be defined as follows: 12 | - with the reflection of the extension are extracted the names of classes, functions and constants 13 | - these names are searched in files of the indicated directory -------------------------------------------------------------------------------- /app.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Command line utilite for searching loaded, but unused php extenstion in files of indicated directory. 9 | 10 | This can be useful if you want to speed up your scripts. 11 | To do this, disable unused extensions in the configuration file of PHP. 12 | Some extensions may not be called out of the code but they may perfom service functions (xDebug, eAccelerator, APC, etc) 13 | Check the list of extensions before switching off 14 | 15 | Caution: The author does not guarantee 100% accuracy of the scanner work 16 | Make sure your applications work after you disable extensions. 17 | 18 | What extension is used, can be defined as follows: 19 | - with the reflection of the extension are extracted the names of classes, functions and constants 20 | - these names are searched in files of the indicated directory 21 | 22 | 23 | 24 | 25 | 26 | Directory of php project(s) 27 | 28 | 29 | 30 | 31 | Names of unused extensions 32 | 33 | 34 | 35 | All extensions are used 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /php_unused_extensions_scanner.php: -------------------------------------------------------------------------------- 1 | \n\n"; 23 | exit; 24 | } 25 | $app=new ExtensionsScanner(); 26 | $result=$app->findUnusedExts($argv[1]); 27 | if(empty($result)) { 28 | echo "\nAll extensions are used\n\n"; 29 | } 30 | else { 31 | echo "\nNames of unused extensions: ".implode(', ',$result)."\n\n"; 32 | } 33 | -------------------------------------------------------------------------------- /unused_extensions_scanner.class.php: -------------------------------------------------------------------------------- 1 | skip_extensions)); 25 | } 26 | 27 | 28 | /** 29 | * Looks for loaded, but unused php extenstion in files of indicated directory. 30 | * 31 | * This can be useful if you want to speed up your scripts. 32 | * To do this, disable unused extensions in the configuration file of PHP. 33 | * Some extensions may not be called out of the code but they may perfom service functions (xDebug, eAccelerator, APC, etc) 34 | * Check the list of extensions before switching off 35 | * 36 | * Caution: The author does not guarantee 100% accuracy of the scanner work 37 | * Make sure your applications work after you disable extensions. 38 | * 39 | * What extension is used, can be defined as follows: 40 | * - with the reflection of the extension are extracted the names of classes, functions and constants 41 | * - these names are searched in files of the indicated directory 42 | * 43 | * @param string $path Directory of php project(s) 44 | * @return array Names of unused extensions 45 | */ 46 | public function findUnusedExts($path) 47 | { 48 | // Validate path 49 | if (!file_exists($path) || !is_dir($path)) 50 | { 51 | throw new Exception("Directory $path does not exists or is not a directory"); 52 | } 53 | 54 | $exts = get_loaded_extensions(); 55 | $exts_keywords = array(); 56 | 57 | // Extract keywords from the php-extensions (names of classes, functions and constants) 58 | foreach ($exts as $ext) 59 | { 60 | if (in_array(strtolower($ext), $this->getSkipExtensions())) 61 | { 62 | continue; 63 | } 64 | 65 | $reflect = new ReflectionExtension($ext); 66 | 67 | $keywords = array_merge($reflect->getClassNames(), array_keys($reflect->getConstants()), array_keys($reflect->getFunctions())); 68 | 69 | if (!is_array($keywords) || count($keywords) == 0) 70 | { 71 | continue; 72 | } 73 | 74 | $exts_keywords[$ext] = $keywords; 75 | } 76 | 77 | // List files from project directory 78 | $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); 79 | foreach ($objects as $object) 80 | { 81 | if ($object->isFile()) 82 | { 83 | $ext = pathinfo($object, PATHINFO_EXTENSION); 84 | 85 | if ($ext == 'php') 86 | { 87 | //echo "Processing of $object\n"; 88 | 89 | // Find for keywords in the file 90 | $temp = file_get_contents($object); 91 | 92 | foreach ($exts_keywords as $ext=>$keywords) 93 | { 94 | foreach ($keywords as $keyword) 95 | { 96 | if (stripos($temp, $keyword) !== FALSE) 97 | { 98 | // Keyword found - this extension is used 99 | //echo "Extension $ext is used\n"; 100 | unset($exts_keywords[$ext]); 101 | break; 102 | } 103 | } 104 | } 105 | 106 | if (count($exts_keywords) == 0) 107 | { 108 | break; 109 | } 110 | } 111 | } 112 | } 113 | 114 | return array_keys($exts_keywords); 115 | } 116 | } --------------------------------------------------------------------------------