What potential issues can arise when using 'HEAD' in PHP requests?

When using 'HEAD' in PHP requests, one potential issue that can arise is that some servers may not properly handle HEAD requests and may return unexpected results or errors. To solve this issue, you can manually set the request method to 'GET' instead of 'HEAD' and then only retrieve the headers from the response.

$url = 'https://example.com';
$options = [
    'http' => [
        'method' => 'GET',
        'header' => 'Content-type: application/json'
    ]
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$headers = array_intersect_key($http_response_header, array_flip(preg_grep('/^content-type:|^content-length:|^last-modified:/i', $http_response_header)));

print_r($headers);