find out which files are called

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yellowrabbit
Forum Newbie
Posts: 1
Joined: Mon Feb 27, 2012 8:43 pm

find out which files are called

Post by yellowrabbit »

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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: find out which files are called

Post by Celauran »

temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: find out which files are called

Post by temidayo »

puma10
Forum Newbie
Posts: 11
Joined: Thu Aug 18, 2011 2:18 pm

Re: find out which files are called

Post by puma10 »

Thanks for the response guys. This looks pretty promising but unfortunately I am still learning so my programming knowledge is lacking a little bit here to get the job done.

Code: Select all

<?php
 // Filename is index.php
 include('test_include.php');
?>
<?php 
 function get_current_files_path($file_name) 
 { 
   //find the current files directory 
   $includes = get_included_files(); 
   $path = ""; 
   for ($i=0; $i < count($includes); $i++) 
   { 
     $path = strstr($includes[$i], $file_name); 
     if ($path != false) 
     { 
       $key = $i; 
       break; 
     } 
   } 
   $path = str_replace(getcwd(), "", $includes[$key]); 
   $path = str_replace("\\", "/", $path); 
   $path = str_replace($file_name, "", $path); 
   $path = ltrim($path, "/"); 
   
   echo $path; 
 } 
?>
<?php 
get_current_files_path('index.php');
?>
Am I suppose to pass index.php to the function or the actual include path. The above is producing no result at all actually. I'm sure there are many errors in my above code, like I said it's a learning processes. Thanks all for being digital teachers ha!
Post Reply