I want to check if a remote image exist. Currently using CURL and based on its response to i can determine if the file exist. However, this takes a fare bit amount of time depending on the image file size also.
Is there a safest and cheapest way of doing a check without doing it offline or using cache?
$ch = curl_init(); // set URL and other appropriate options /*--Note: if in sabre proxy, please activate the last 4 lines--*/ $options = array( CURLOPT_URL => $img, CURLOPT_HEADER => false, // get the header CURLOPT_NOBODY => true, // body not required CURLOPT_RETURNTRANSFER => false, // get response as a string from curl_exec, not echo it CURLOPT_FRESH_CONNECT => false, // don't use a cached version of the url CURLOPT_FAILONERROR => true, CURLOPT_TIMEOUT => 5 ); curl_setopt_array($ch, $options); if(!curl_exec($ch)) { return FALSE; } $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); return ($httpcode<400);
HEAD, notHEADER.