Last active
February 21, 2024 11:39
-
-
Save jrivero/741973 to your computer and use it in GitHub Desktop.
Kill process if is modified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Autokill { | |
var $start_mtime_included_files = array(); | |
function Autokill() { $this->__construct(); } | |
function __construct() { | |
clearstatcache(); | |
$files = get_included_files(); | |
foreach ((array)$files as $file) | |
$this->start_mtime_included_files[$file] = filemtime($file); | |
} | |
function kill_if_modified() { | |
clearstatcache(); | |
$modified = false; | |
$files = get_included_files(); | |
foreach ((array)$files as $file) { | |
if (!array_key_exists($file, $this->start_mtime_included_files)) | |
$this->start_mtime_included_files[$file] = filemtime($file); | |
else if (filemtime($file) != $this->start_mtime_included_files[$file]) { | |
echo $file."[".$this->start_mtime_included_files[$file]."<".filemtime($file)."] \n"; | |
$modified = true; | |
break; | |
} | |
} | |
if ($modified) | |
$this->kill(); | |
return $modified; | |
} | |
function kill() { | |
$pid = getmypid(); | |
$cmd = "kill -9 ".(int)$pid; | |
echo $cmd."\n"; | |
shell_exec($cmd); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment