Search code examples
phpwindows-server

How to watch which php files have been executed within a period of time?


Some website article pictures often be deleted. I want a tool can watch which php files have been executed within a period of time.

The envirment is apache+mysql on windows server2008 R2


Solution

  • use this to get the file name:

     $fname=   $_SERVER["SCRIPT_FILENAME"];
    

    or

    $fname=  basename(__FILE__, '.php'); //without extension
    

    and use this to log it to a file :

    $logfile = fopen("log.txt", "w") or die("Unable to open file!");
    $txt = $fname;
    fwrite($logfile, $txt);
    $ts=time();
    fwrite($logfile, $ts);
    fclose($logfile);
    

    you can wrap it in a function and call it in the beginning of each php file.