First of all, I wouldn't recommend this unless it's the last possible option. Knowing when a file is ready is better than guessing whether a copy operation has finished.
Even if a file no longer grows doesn't mean the contents are actually valid; perhaps the copy operation was aborted and a partial file remains; without a checksum you would have no idea whether the file can actually be used.
function waitFor($file, $delay = 1)
{
if (file_exists($file)) {
$current_size = filesize($file);
while (true) {
sleep($delay);
clearstatcache(false, $file); // requires >= 5.3
$new_size = filesize($file);
if ($new_size == $current_size) {
break;
}
$current_size = $new_size;
}
return $current_size;
} else {
return false;
}
}
waitFor('/path/to/file', 2);
// consider file is ready if size not changed for two seconds