1. <?php
  2. /**
  3. * Monitors the state of binary files for exploratory work with synchronous execution.
  4. *
  5. * @param string $filepath The path to the binary file.
  6. * @param int $interval The interval (in seconds) between checks.
  7. * @return void
  8. */
  9. function monitorBinaryFile(string $filepath, int $interval): void
  10. {
  11. if (!file_exists($filepath)) {
  12. echo "Error: File not found: $filepath\n";
  13. return;
  14. }
  15. echo "Monitoring $filepath...\n";
  16. while (true) {
  17. // Get file size
  18. $fileSize = filesize($filepath);
  19. // Check if the file exists and is accessible
  20. if (!file_exists($filepath) || !is_readable($filepath)) {
  21. echo "Error: File disappeared or became inaccessible. Exiting.\n";
  22. exit;
  23. }
  24. // Output current file size
  25. echo "File size: $fileSize bytes\n";
  26. // Sleep for the specified interval
  27. sleep($interval);
  28. }
  29. }
  30. // Example usage:
  31. // monitorBinaryFile('/path/to/your/binary_file.bin', 5);
  32. ?>

Add your comment