tags:

views:

121

answers:

3

I'm looking into removing php files that are no longer used on my site. I can use something like get_included_files to show the included files, but that would mean I would have to put it on every child page. If I put it on a parent page, it won't show me the child page that called it.

Has anybody else run into a similar situation? If so, what did you do to remove unused php files?

+2  A: 

The best and most efficient way is to manually browse through all the files and pick out which ones are not used anymore. That way you delete all the ones you don't need and don't accidentally delete ones you still do need. You really shouldn't rely on an automated process for something like this.

animuson
A: 

Hopefully, you have put files that don't interact with browsers in their own directory. If that is the case, its relatively simple to use grep to find out what is still including or requiring them.

If not, pull a local copy, rename files one by one and see what breaks. I was about to suggest using regex to figure out what files actually output HTML, but that would not significantly narrow the possibility of breakage.

In any event, this process presents a good opportunity to better organize your code. I really do feel your pain, I'm going back on sites I launched five years ago and doing the same thing.

Tim Post
A: 

Though I agree with animuson on that the last decision should be made by the developer/maintainer you can use some tools to assist you, to pick the files you want to look at and to evaluate their "usefulness".
E.g. you could set up the apc cache with a ttl of 0 and enough memory to avoid the removal of (all) elements/files. Then some time later retrieve the cache statistics and compare it to the list of files.
There are other tools out there, like e.g. nWire. But I found that for existing/running projects apc is more than sufficient because it not only tells you about completely orphaned files but rarely used scripts you might want to remove/rewrite/re-arrange/whatever.

VolkerK