Solved

Determine file dependencies of a script?

Posted on 2008-10-14
6
255 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to access a remote mysql database with xampp 3 23
Wordpress Security 29 46
Wordpress Only run code if on a certain page 11 22
Ajax and PHP 9 29
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

791 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