yellowrabbit Posted February 28, 2012 Share Posted February 28, 2012 Hello I have a php website. I am trying to trace (find out) which files are called when a page is displayed. For example on certain pages that get displayed it may call up to 6-7 files. I would like to know the name of the files and the order they are called. As through out the code there is a lot of include_once("global/global.libs.php"); Is there any may to easily trace this without having to go through page by page on the code and try to figure out what is happening. Essentially I just want the file name eg global/global.libs.php logged somewhere Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/ Share on other sites More sharing options...
blacknight Posted February 28, 2012 Share Posted February 28, 2012 $included_files = get_included_files(); foreach ($included_files as $filename) { echo "$filename\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1321917 Share on other sites More sharing options...
yellowrabbit Posted February 28, 2012 Author Share Posted February 28, 2012 Thank you for the quick reply. Would I just include this peice of code at the TOP of the main file which is called. Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1321926 Share on other sites More sharing options...
Ruddy Posted February 28, 2012 Share Posted February 28, 2012 Put that in the page where you want to see the included pages. It will then print there names for you. My guess is that if you put that at the top of the page it would print them in order of top to bottom. Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1321933 Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2012 Share Posted February 28, 2012 get_included_files only gets the actual files that have been included/required at the time it is called. You would need to use it in a register_shutdown_function to get all the actual included/required files for any particular page request. Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1321934 Share on other sites More sharing options...
yellowrabbit Posted February 28, 2012 Author Share Posted February 28, 2012 I am not actually sure how I use the register_shutdown_function() with get_included_files() Also where do I place this code. Can you please explain. Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1321957 Share on other sites More sharing options...
blacknight Posted February 28, 2012 Share Posted February 28, 2012 function shutdown() { $included_files = get_included_files(); foreach ($included_files as $filename) { echo "$filename\n"; } } register_shutdown_function('shutdown'); and thats how its done the function will only run once the page pas finished all other functions its queued at the end of the process tree in php Quote Link to comment https://forums.phpfreaks.com/topic/257902-find-out-which-files-are-called/#findComment-1322002 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.