Determining file inclusion for files
Is there a way to determine how many times require_on开发者_如何转开发ce or any other inclusion method is being called on a specific file? I had an infinite loop issue with some kind of inclusion error, it's gone now, but I'd like to be certain I'm not excessively including files.
I would use a text search software that will show me all occurrences of the page name across all the files on your site. This would return any require, include, etc that references it, and the file it is in. Most good IDE's will do this.
My simple idea using text file on server... for example
extern.php
<?php
$file = 'count.txt';
$v = 1;
if (file_exists($file)) {
$fp = fopen($file, 'r');
$v = fgets($fp) + 1;
fclose($fp);
}
$fp = fopen($file, 'w');
fputs($fp, $v);
fclose($fp);
echo "counter: $v";
?>
index.php
<?php
include('extern.php');
?>
This will print out "include-counter" on every include of extern.php
file. Result has been stored in text file count.txt
.
Note: Don't use relative file path (like I did in example) because script may be called from different directories.
精彩评论