How can one verify if a cache is being utilized when loading data from an external server in PHP?

When loading data from an external server in PHP, you can verify if a cache is being utilized by checking if the data is being retrieved from the cache instead of making a new request to the external server. You can achieve this by implementing a caching mechanism such as using PHP's built-in caching functions like `file_get_contents()` with a cache expiration time.

$cacheFile = 'cache/data.json';
$cacheExpiration = 3600; // 1 hour

if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < $cacheExpiration)) {
    $data = file_get_contents($cacheFile);
} else {
    $data = file_get_contents('http://external-server/data');
    file_put_contents($cacheFile, $data);
}

// Use the $data variable for further processing