Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(filemtime('myfile.txt') > $result_set['filemtime']) {
- // file was modified
- }
- $modifiedTs = filemtime($filename);
- if ($modifiedTs != $lastModificationTs){
- echo "$filename was modified!";
- }
- class ApplicationLogger {
- private $logfile, $path;
- public function __construct() {
- $this->logfile = 'error.log';
- $this->path = '/var/log/apache2/';
- }
- public function logState() {
- $files = array(
- 'target' => $this->path . $this->logfile,
- 'lastmod' => $this->path . $this->logfile . '_lastmod'
- );
- if (file_exists($files['lastmod']) && file_exists($files['target'])) {
- $lfh = fopen($files['lastmod'], 'r');
- while (!feof($lfh)) {
- $lines[] = fgets($lfh);
- }
- fclose($lfh);
- }
- $modified = false;
- /**
- * check if we have a matching hash.
- */
- if (isset($lines) && filemtime($files['target']) != $lines[0]) { // mod time mismatch
- if (md5_file($files['target']) != $lines[1]) { // content modified
- $modified = true;
- }
- }
- /**
- * update or create the lastmod file
- */
- if (!file_exists($files['lastmod']) || $modified) {
- $current_mod = filemtime($files['target']) . "n" . md5_file($files['target']);
- file_put_contents($files['lastmod'], $current_mod);
- $modified = true;
- }
- return $modified;
- }
- }
- $mod = new ApplicationLogger();
- if ($mod->logState()) {
- // changed do something
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement