Solved

Determine file dependencies of a script?

Posted on 2008-10-14
6
253 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:RQuadling
RQuadling 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:RQuadling
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Expert Comment

by:RQuadling
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now