<?php
/**
* Monitors the state of binary files for exploratory work with synchronous execution.
*
* @param string $filepath The path to the binary file.
* @param int $interval The interval (in seconds) between checks.
* @return void
*/
function monitorBinaryFile(string $filepath, int $interval): void
{
if (!file_exists($filepath)) {
echo "Error: File not found: $filepath\n";
return;
}
echo "Monitoring $filepath...\n";
while (true) {
// Get file size
$fileSize = filesize($filepath);
// Check if the file exists and is accessible
if (!file_exists($filepath) || !is_readable($filepath)) {
echo "Error: File disappeared or became inaccessible. Exiting.\n";
exit;
}
// Output current file size
echo "File size: $fileSize bytes\n";
// Sleep for the specified interval
sleep($interval);
}
}
// Example usage:
// monitorBinaryFile('/path/to/your/binary_file.bin', 5);
?>
Add your comment