Tracking include and require statements

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
MmmVomit
Forum Newbie
Posts: 4
Joined: Wed May 27, 2009 1:09 am

Tracking include and require statements

Post by MmmVomit »

I'm working on trimming away old and unused scripts from a rather large project. The only problem is that we have a real tangle of include and require statements.

I can gather statistics from Apache's log files to help identify pages that aren't being directly accessed by users, but when one file is included by another, that's all being done by PHP, right? Is there any way to create a log of the files that PHP accesses?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Tracking include and require statements

Post by onion2k »

A combination of register_shutdown_function() to update a log file, and get_included_files() to build a list of which files were included should do the trick.
MmmVomit
Forum Newbie
Posts: 4
Joined: Wed May 27, 2009 1:09 am

Re: Tracking include and require statements

Post by MmmVomit »

Yeah, that looks like it could work. I could also use the auto_prepend_file directive to make it run on every page that gets loaded.

Since this will happen with every page load, I'll have to make sure this doesn't affect performance too much.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Tracking include and require statements

Post by Weirdan »

There's a dedicated extension for just what you need: http://pecl.php.net/package/inclued
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Tracking include and require statements

Post by alex.barylski »

Weirdan...dude your just on the ball today man...thats a pretty rockin extension :)

Ideally I am trying to figure out a way to determine every methods dependencies (in terms of functions, classes and/or includes.
Post Reply