protected function checkChangedFiles($restartWorkers = true)
{
if ($this->inReload) {
return false;
}
clearstatcache();
$reload = false;
$filePath = '';
$start = microtime(true);
foreach ($this->filesToTrack as $idx => $filePath) {
if (!file_exists($filePath)) {
continue;
}
$currentFileMTime = filemtime($filePath);
if (isset($this->filesLastMTime[$filePath])) {
if ($this->filesLastMTime[$filePath] !== $currentFileMTime) {
$this->filesLastMTime[$filePath] = $currentFileMTime;
$md5 = md5_file($filePath);
if (!isset($this->filesLastMd5[$filePath]) || $md5 !== $this->filesLastMd5[$filePath]) {
$this->filesLastMd5[$filePath] = $md5;
$reload = true;
//since chances are high that this file will change again we
//move this file to the beginning of the array, so next check is way faster.
unset($this->filesToTrack[$idx]);
array_unshift($this->filesToTrack, $filePath);
break;
}
}
} else {
$this->filesLastMTime[$filePath] = $currentFileMTime;
}
}
if ($reload && $restartWorkers) {
$this->output->writeln(sprintf("<info>[%s] File changed %s (detection %f, %d). Reload workers.</info>", date('d/M/Y:H:i:s O'), $filePath, microtime(true) - $start, count($this->filesToTrack)));
$this->restartWorker();
}
return $reload;
}