0

I have a complex web application, which reads and writes a myriad of files (xml, css, js, jpg etc.). For cleaning up purposes, in a shutdown function I want to log the filenames which were read (and written) using one of the various file methods in PHP, e.g. fread(), file_get_contents(), readfile() and whatever.

I couldn't find a similar approach like get_included_files() and I'm quite sure there is no simple method to achiveve that. But does somebody know of a probably more complex logic?

Anse
  • 1,573
  • 12
  • 27

1 Answers1

1

No but you could create a wrapper function that logs all that information for you.

<?

$__modifiedFiles = array();

function fetch_file($file) {
    global $__modifiedFiles;
    $__modifiedFiles[] = $file;
    return file_get_contents($file);
}

function get_modified_files() {
    global $__modifiedFiles;
    return $__modifiedFiles;
}

Or... perhaps you could use incron to capture events that happened on the filesystem:

http://manpages.ubuntu.com/manpages/intrepid/man5/incrontab.5.html

Or... perhaps you could recursively look for modified files using the find command:

How to recursively find and list the latest modified files in a directory with subdirectories and times?

Community
  • 1
  • 1
Clay
  • 4,700
  • 3
  • 33
  • 49
  • The incrontab approach looks very promising, although most complicated here. Perhaps I'll go for the wrapper logic as this is simple and works without 3rd party software. – Anse Jan 15 '16 at 09:22
  • I ended up in running a PHP script every 10 minutes, checking fileatime() of all files in my document root, logging those filenames which were modified since the last execution to a statistic table in my database. Only crux is that the access time does not seem to get updated on every read. Probably due to the "relatime" mount option of the filesystem. – Anse Jan 15 '16 at 10:55