开发者

Getting rid of unused php files

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?


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.


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.


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.


It is possible to write a program that lists all the files used by the web server in a given request. I would make it so that this script is run on all your pages, a good place to put this is a configuration file or something that is always included. Then make it insert the files in a database every time it finds a new files. After the course of a time or testing when you have made sure that all functionalitys and pages have been executed. (Perhaps using a crawler, sitemap generators, or a period of time that makes sense to you) then you can move all these files in another script to a new folder where only the requirements are left.

Other ways to do this other than bootstrapping php to do this is to use an apache module, I hope that gives you some ideas.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜