What best practices should be followed when using the SplFileInfo class in PHP to retrieve file modification times for monitoring purposes?

When using the SplFileInfo class in PHP to retrieve file modification times for monitoring purposes, it is important to ensure that the file actually exists before attempting to access its properties. This can prevent errors and exceptions from being thrown when trying to access non-existent files. Additionally, it is recommended to use the getLastModified() method provided by the SplFileInfo class to retrieve the last modification time of the file.

$file = new SplFileInfo('path/to/file.txt');

if ($file->isFile()) {
    $lastModifiedTime = $file->getMTime();
    echo "Last modified time: " . date('Y-m-d H:i:s', $lastModifiedTime);
} else {
    echo "File does not exist.";
}