一个更好的方法来测试是视频还是404页面


A better way to test if video or a 404 page?

我正在使用以下代码来查看视频是否已准备好嵌入我的网站。如果视频是404页,它将退出,如果是其他内容,当然包括视频,它将继续。理论上。

我困惑了大约一个小时,为什么它停止工作,但一定是因为视频现在已经准备好了,我的代码试图将整个视频包括在我的代码中,而不仅仅是得到一个标题或其他什么。

有更好的方法吗??

$url=$videourl;
$handle = curl_init($url);
curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
/* Get the HTML or whatever is linked in $url. */
$response = curl_exec($handle);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
  exit("video not ready!"); 
}
curl_close($handle);

听起来像是要发出HEAD请求。用途:

curl_setopt($handle, CURLOPT_NOBODY, true);