0

I recently became involved with PHP. I have a very old website with 800+ modules and suspect that some of the php files are not referenced.

I am using Notepad++ Find in Files option to search every php file name. This is going to take a long time using this method.

Is there a better way to determine dead php files?

SheetJS
  • 22,470
  • 12
  • 65
  • 75
Mel
  • 119
  • 1
  • 9
  • Nirk, I'm not looking at dead code within a php file. I am looking to see if the entire php file is useless. – Mel Oct 15 '13 at 21:27

3 Answers3

0

the best way would be to use xdebug's code coverage

Its most commonly used for seeing how much code is excecuted duing a unit test, But you can also use it to find dead code.

Start xdebug and click around in as many places as you can. then look at the resulting files. Its not an easy or quick job though.

When xdebug has finished, Youl will have a list of files (and lines) you can then try and remove all files not mentioned

exussum
  • 18,275
  • 8
  • 32
  • 65
  • I understand what you are trying to do with code coverage. Thanks for the input. – Mel Oct 16 '13 at 00:05
0

Another approach would be to look for a windows GREP tool. Applying it recursively -starting with the default page.

See this closed?? answer:

What are good grep tools for Windows?

Particularly the Gnu Grep answer with xargs (and recursive grepping). If your script names and methods of calling them are reasonably consistent, you should be able to create a structure tree of the script calls in your system, as well as a list of used (and by elimination unused) scripts to focus your checking.

I would assume that the output from such an exercise cannot be absolutely relied on without a deal of duble-checking but it will hopefully speed the process up considerably. Good luck.

Community
  • 1
  • 1
Arthur Nicoll
  • 391
  • 1
  • 2
  • 8
  • I understand this approach. Maybe I could write a simple script that goes through the directories searching each php file using the grep tool. The results would be pushed to a text file. – Mel Oct 16 '13 at 00:08
0

I would upgrade to an actual IDE instead of using a text editor. Any commonly used IDE will be able to search for all references to a given string or class name across ALL of your project files very quickly. I like PHP Storm but it's not free. Eclipse and Aptana are free alternatives.

Neil Girardi
  • 4,533
  • 1
  • 28
  • 45
  • How? I am using NetBeans as my IDE. How can an IDE determine the entire php file that is included in a project is not referenced at all via an include/require or any other method? – Mel Oct 16 '13 at 16:33
  • Hi Mel, I don't use NetBeans so I'm not sure what the exact menu option would be but it's likely to be a variation of control + F (Windows or Linux) or command + F (OS X). In Webstorm I can go to Find in Path from the Edit menu. From there I can select "entire project" and type the name of a file. This will show me every reference to the name of that file in the entire codebase of the project I have open. The results are organized by directories and files. I can click on a specific line of a file from within the results window and it will open that file and place my cursor right on that line. – Neil Girardi Oct 16 '13 at 18:16