Reputation: 1294
I need to check if remote file are online and they didn't change. The problem is that those files are big, so I want to read the http header only and then abort the request. The result would be based on response status code and content length field.
How can I do it in PHP?
Upvotes: 0
Views: 575
Reputation: 85468
You can use the get_headers()
function.
If you prefer cURL, you can use CURLOPT_NOBODY
:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = curl_exec($ch);
Upvotes: 5