src/ProcessManager.php
protected function checkChangedFiles($restartSlaves = true)
    {
        if ($this->inChangesDetectionCycle) {
            return false;
        }

        $start = microtime(true);
        $hasChanged = false;

        $this->inChangesDetectionCycle = true;

        clearstatcache();

        foreach ($this->filesLastMTime as $filePath => $knownMTime) {
            if (!file_exists($filePath)) {
                continue;
            }

            $actualFileTime = filemtime($filePath);
            $actualFileHash = md5_file($filePath);

            if ($knownMTime !== $actualFileTime && $this->filesLastMd5[$filePath] !== $actualFileHash) {

                // update tracked entry metadata
                $this->filesLastMd5[$filePath] = $actualFileHash;
                $this->filesLastMTime[$filePath] = $actualFileTime;

                $this->output->writeln(
                    sprintf("<info>[%s] File %s has changed.</info>", date('d/M/Y:H:i:s O'), $filePath)
                );
                $hasChanged = true;
                break;
            }
        }

        if ($hasChanged) {
            $this->output->writeln(
                sprintf(
                    "<info>[%s] At least one of %u known files was changed. Reloading workers.</info>",
                    date('d/M/Y:H:i:s O'),
                    count($this->filesLastMTime)
                )
            );

            if ($this->output->isVeryVerbose()) {
                $this->output->writeln(
                    sprintf("Changes detection cycle length = %.3f ms", (microtime(true) - $start) * 1000)
                );
            }

            if ($restartSlaves) {
                $this->restartSlaves();
            }
        }

        $this->inChangesDetectionCycle = false;

        return $hasChanged;
    }
protected function checkChangedFiles($restartSlaves = true)
    {
        if ($this->inChangesDetectionCycle) {
            return false;
        }

        $start = microtime(true);
        $hasChanged = false;

        $this->inChangesDetectionCycle = true;

        clearstatcache();

        foreach ($this->filesLastMTime as $filePath => $knownMTime) {
            if (!file_exists($filePath)) {
                continue;
            }

            $actualFileTime = filemtime($filePath);
            $actualFileHash = md5_file($filePath);

            if ($knownMTime !== $actualFileTime && $this->filesLastMd5[$filePath] !== $actualFileHash) {

                // update tracked entry metadata
                $this->filesLastMd5[$filePath] = $actualFileHash;
                $this->filesLastMTime[$filePath] = $actualFileTime;

                $this->output->writeln(
                    sprintf("<info>[%s] File %s has changed.</info>", date('d/M/Y:H:i:s O'), $filePath)
                );
                $hasChanged = true;
                break;
            }
        }

        if ($hasChanged) {
            $this->output->writeln(
                sprintf(
                    "<info>[%s] At least one of %u known files was changed. Reloading workers.</info>",
                    date('d/M/Y:H:i:s O'),
                    count($this->filesLastMTime)
                )
            );

            if ($this->output->isVeryVerbose()) {
                $this->output->writeln(
                    sprintf("Changes detection cycle length = %.3f ms", (microtime(true) - $start) * 1000)
                );
            }

            if ($restartSlaves) {
                $this->restartSlaves();
            }
        }

        $this->inChangesDetectionCycle = false;

        return $hasChanged;
    }
protected function checkChangedFiles ( $ restartSlaves = true ) { if ( $ this -> inChangesDetectionCycle ) { return false ; } $ start = microtime ( true ) ; $ hasChanged = false ; $ this -> inChangesDetectionCycle = true ; clearstatcache ( ) ; foreach ( $ this -> filesLastMTime as $ filePath => $ knownMTime ) { if ( ! file_exists ( $ filePath ) ) { continue ; } $ actualFileTime = filemtime ( $ filePath ) ; $ actualFileHash = md5_file ( $ filePath ) ; if ( $ knownMTime !== $ actualFileTime && $ this -> filesLastMd5 [ $ filePath ] !== $ actualFileHash ) { // update tracked entry metadata $ this -> filesLastMd5 [ $ filePath ] = $ actualFileHash ; $ this -> filesLastMTime [ $ filePath ] = $ actualFileTime ; $ this -> output -> writeln ( sprintf ( "<info>[%s] File %s has changed.</info>" , date ( 'd/M/Y:H:i:s O' ) , $ filePath ) ) ; $ hasChanged = true ; break ; } } if ( $ hasChanged ) { $ this -> output -> writeln ( sprintf ( "<info>[%s] At least one of %u known files was changed. Reloading workers.</info>" , date ( 'd/M/Y:H:i:s O' ) , count ( $ this -> filesLastMTime ) ) ) ; if ( $ this -> output -> isVeryVerbose ( ) ) { $ this -> output -> writeln ( sprintf ( "Changes detection cycle length = %.3f ms" , ( microtime ( true ) - $ start ) * 1000 ) ) ; } if ( $ restartSlaves ) { $ this -> restartSlaves ( ) ; } } $ this -> inChangesDetectionCycle = false ; return $ hasChanged ; }
Checks if tracked files have changed. If so, restart all slaves.

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.

@param bool $restartSlaves

@return bool
Checks if tracked files have changed . If so restart all slaves .