PHPPM\ProcessManager::checkChangedFiles PHP Méthode

checkChangedFiles() protected méthode

This approach uses simple filemtime to check against modifications. It is using this technique because all other file watching stuff have either big dependencies or do not work under all platforms without installing a pecl extension. Also this way is interestingly fast and is only used when debug=true.
protected checkChangedFiles ( boolean $restartWorkers = true ) : boolean
$restartWorkers boolean
Résultat boolean
    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;
    }