栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

get_headers不一致

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

get_headers不一致

问题与域名的长度无关,只是域名是否存在。

您正在使用DNS服务,该服务将不存在的域解析到服务器,该服务器为您提供“友好的”错误页面,该页面返回200响应码。这意味着它也不是一个问题

get_headers()
,它完全依赖于合理的DNS查找。

在不对所使用的每个环境进行硬编码的情况下解决此问题的方法可能类似于以下内容:

// A domain that definitely does not exist. The easiest way to guarantee that// this continues to work is to use an illegal top-level domain (TLD) suffix$testDomain = 'idontexist.tld';// If this resolves to an IP, we know that we are behind a service such as this// We can simply compare the actual domain we test with the result of this$badIP = gethostbyname($testDomain);// Then when you want to get_headers()$url = 'http://www.domainnnnnnnnnnnnnnnnnnnnnnnnnnnn.com/CraxyFile.jpg';$host = parse_url($url, PHP_URL_HOST);if (gethostbyname($host) === $badIP) {  // The domain does not exist - probably handle this as if it were a 404} else {  // do the actual get_headers() stuff here}

您可能希望以某种方式缓存对的第一次调用的返回值

gethostbyname()
,因为您知道自己正在查找不存在的名称,这通常需要几秒钟的时间。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/421694.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号