How can the clearstatcache() function be effectively used to prevent caching issues in PHP file existence checks?

When performing file existence checks in PHP, the clearstatcache() function can be used to clear the file status cache, preventing any potential caching issues. This ensures that the most up-to-date information about the file's existence is retrieved each time the check is made.

// Check file existence
$file = 'example.txt';

// Clear the file status cache
clearstatcache();

if (file_exists($file)) {
    echo "File exists.";
} else {
    echo "File does not exist.";
}