Solved

Determine file dependencies of a script?

Posted on 2008-10-14
6
258 Views
Last Modified: 2013-12-15
Hello,

Anyone know a good way to determine what the file dependencies of a particular script are? I need not just the files immediately included in the file but ALL the files that file needs to run.

So, say I've got script A, and it includes class_B.php, and class B requires_once(file_C) and file_C needs file D.

Any way to figure out, from script A, what file D is?
0
Comment
Question by:dnatal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 300 total points
ID: 22718820
You could try calling get_included_files: http://www.php.net/manual/en/function.get-included-files.php
0
 
LVL 40

Assisted Solution

by:Richard Quadling
Richard Quadling earned 200 total points
ID: 22720365
If you have a lot of scripts which you want to track down, then you can use a registered shutdown function invoked by using the auto_prepend_file facility to use get_included_files() and store then somewhere for each script.

Watch this space...
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22720509
Something like the snippet below.

In your php.ini file you will have a line with ...

;auto_prepend_file=

If you save the snippet somewhere accessible to the web server (say Z:\LogIncludes.php) and change the ini file to be ...

auto_prepend_file=Z:/LogIncludes.php

Every script you run will have the includes logged for you.

If you run the file by itself, it should also log!


Z:\Usage>dir /s /b
Z:\Usage\58d404442823079089828b569b40f84c.log

Z:\Usage>type 58d404442823079089828b569b40f84c.log
Z:\logIncludes.php

array (
  0 => 'Z:\\logIncludes.php',
)



<?php
function logIncludes() {
	// Build string containing filename and included files.
	$s_Data = $_SERVER['PHP_SELF'] . PHP_EOL . PHP_EOL . var_export(get_included_files(), True);
 
	// Use a hash of the filename to store the data.
	// You will need to amend the path below to somewhere useful for you.
	$s_LogFile = 'Z:/Usage/' . md5($_SERVER['PHP_SELF']) . '.log';
 
	// Make sure the directory exists.
	mkdir(dirname($s_LogFile), 0777, True);
 
	// Log the file if it doesn't already exist.
	if (!file_exists($s_LogFile)) {
		file_put_contents($s_LogFile, $s_Data);
	}
}
 
register_shutdown_function('logIncludes');

Open in new window

0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 40

Expert Comment

by:Richard Quadling
ID: 22720516
I use a hash as this will reduce the complexity of the filenames in subdirectories. You COULD just save a log file next to each script, but I don't know if that is appropriate for you.


0
 
LVL 2

Author Comment

by:dnatal
ID: 22736050
get_included_files() is what I was looking for. Kinda wish it was a multidimensional array so I could see the dependency structures, or even just have parent file as array key, but it'll work.

All great answers and I really appreciate all the help.
0
 
LVL 2

Author Closing Comment

by:dnatal
ID: 31506040
Really appreciate the help. Split the points because they're both valid answers.
0

Featured Post

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question