Skip to content

Commit 2fcde38

Browse files
authored
Improve change detection, avoid multiple restarts when 2 or more files are changed/removed (php-pm#530)
1 parent 871bee4 commit 2fcde38

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/ProcessManager.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ public function checkChangedFiles()
947947
}
948948

949949
$start = \microtime(true);
950-
$hasChanged = false;
950+
$numChanged = 0;
951951

952952
\clearstatcache();
953953

@@ -961,20 +961,16 @@ public function checkChangedFiles()
961961
}
962962

963963
//If the file doesn't exist anymore, remove it from the list of tracked files and restart the workers
964-
if (! \file_exists($filePath)) {
964+
if (!\file_exists($filePath)) {
965965
unset($this->filesLastMd5[$filePath]);
966966
unset($this->filesLastMTime[$filePath]);
967967

968968
$this->output->writeln(
969969
\sprintf("<info>[%s] File %s has been removed.</info>", \date('d/M/Y:H:i:s O'), $filePath)
970970
);
971-
$hasChanged = true;
972-
973-
break;
974-
}
975-
971+
$numChanged++;
976972
//If the file modification time has changed, update the metadata and check its contents.
977-
if ($knownMTime !== $actualFileTime = \filemtime($filePath)) {
973+
} elseif ($knownMTime !== ($actualFileTime = \filemtime($filePath))) {
978974
//update time metadata
979975
$this->filesLastMTime[$filePath] = $actualFileTime;
980976
if ($this->output->isVeryVerbose()) {
@@ -989,18 +985,17 @@ public function checkChangedFiles()
989985
$this->output->writeln(
990986
\sprintf("<info>[%s] File %s has changed.</info>", \date('d/M/Y:H:i:s O'), $filePath)
991987
);
992-
$hasChanged = true;
993-
994-
break;
988+
$numChanged++;
995989
}
996990
}
997991
}
998992

999-
if ($hasChanged) {
993+
if ($numChanged > 0) {
1000994
$this->output->writeln(
1001995
\sprintf(
1002-
"<info>[%s] At least one of %u known files was changed. Reloading workers.</info>",
996+
"<info>[%s] %u of %u known files was changed or removed. Reloading workers.</info>",
1003997
\date('d/M/Y:H:i:s O'),
998+
$numChanged,
1004999
\count($this->filesLastMTime)
10051000
)
10061001
);
@@ -1016,7 +1011,7 @@ public function checkChangedFiles()
10161011
));
10171012
}
10181013

1019-
return $hasChanged;
1014+
return $numChanged > 0;
10201015
}
10211016

10221017
/**

0 commit comments

Comments
 (0)