4

When inheriting the maintenance programming of a large web application that has many php5 scripts (4000+), what is the best way to determine which scripts are no longer in use and can probably be removed?

  • What's in my mind would be a script that goes trough the directory collect all script names and the open's every script and search if a script is anywhere included or used! (Don't think it's the best solution but it could work) – Rizier123 Dec 04 '14 at 06:25
  • Maybe there is some sort of mechanism in php5 (or a module) to log all include/requires? – Darren Campbell Dec 04 '14 at 06:27
  • you could create a new folder, paste in the master index.php and then copy in that file one by one all the scripts that php will be whining about... a monk's work, to be certain – Félix Adriyel Gagnon-Grenier Dec 04 '14 at 06:31
  • 1
    possible duplicate of [How can I find unused functions in a PHP project](http://stackoverflow.com/questions/11532/how-can-i-find-unused-functions-in-a-php-project) – EternalHour Dec 04 '14 at 06:32
  • Finding unused functions is one part of the problem... these scripts are using conditional includes etc. Another idea I had was to gather script accesses via apache2 access logs over a week or so. – Darren Campbell Dec 04 '14 at 06:36
  • Created php5 extension here https://github.com/campbeld1 that logs file names to syslog. Will accumulate a lot, however, another process could remove duplicates from the log. Then the set of scripts in the source base could be compared to the set in the de-duplicated logs. – Darren Campbell Dec 05 '14 at 00:19

1 Answers1

1

There is a project Dead Code Detector (DCD).

It finds functions that are never called, which may help to clean up even the files you keep in production.

For finding out unused files, no firm software/algorithm exists for PHP (at least as per my knowledge).

For finding unused files, I think we should do it manually.

Pupil
  • 23,834
  • 6
  • 44
  • 66
  • I'll accept this as the answer although "manually with some automated guidance" might be a better answer. It doesn't seem to be the best approach to work with a large code-base by opening up and inspecting every single file. There are often patterns in the code-base that can be exploited by automation. – Darren Campbell Jan 07 '15 at 23:14