Checking if a CDN file is available
In my experience no, using curl is much better an reliable. I use the following code in one of my projects, this always works (and allows redirects, if you don't want to set CURLOPT_MAXREDIRS to 0).

&lt;?php

/**
 * Check if the URL is reachable.
 *
 * @param string $url
 *   The URL to check.
 * @return this
 * @throws \LogicException
 */
public function checkReachability($url) {
  $ch = curl_init($url);
  curl_setopt_array($ch, [
    CURLOPT_AUTOREFERER    =&gt; true,
    CURLOPT_CONNECTTIMEOUT =&gt; 5,
    CURLOPT_ENCODING       =&gt; "",
    CURLOPT_FOLLOWLOCATION =&gt; true,
    CURLOPT_MAXREDIRS      =&gt; 1,
    CURLOPT_NOBODY         =&gt; true,
    CURLOPT_SSL_VERIFYHOST =&gt; false,
    CURLOPT_SSL_VERIFYPEER =&gt; false,
    CURLOPT_TIMEOUT        =&gt; 5,
    // It's very important to let other webmasters know who's probing their servers.
    CURLOPT_USERAGENT      =&gt; "Mozilla/5.0 (compatible; StackOverflow/0.0.1; +https://codereview.stackexchange.com/)",
  ]);
  curl_exec($ch);
  $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  curl_close($ch);
  if ($code !== 200) {
    throw new LogicException("The URL doesn’t exists (more specifically isn’t reachable).");
  }
  return $this;
}

?&gt;


Of course you have the problem that you don't always have curl available, a fallback would be.

&lt;?php

// PHP 5.3+
stream_context_set_default(array("http" =&gt; array(
  "method"     =&gt; "HEAD",
  "user_agent" =&gt; "Mozilla/5.0 (compatible; StackOverflow/0.0.1; +https://codereview.stackexchange.com/)",
)));

set_error_handler(function ($errno, $errstr, $errfile, $errline ) {
  throw new LogicException("The URL doesn’t exists (more specifically isn’t reachable).");
});
$headers = get_headers($url);
restore_error_handler();

// String comparisons should be made with ==
if (!isset($headers[0]) || substr($headers[0], 9, 3) != "200") {
  throw new LogicException("The URL doesn’t exists (more specifically isn’t reachable).");
}

?&gt;