PHP Curl 获取 HTTP 代码,而不是整个文档
我在PHP中使用curl在请求某些文件时检查HTTP代码,我试图让我的速度运行得更快,所以我想知道是否有一种方法可以让它获取HTTP代码而不实际获取网页远程主机
I'm using curl in PHP to check the HTTP code when requesting some files, I'm trying to make my speed run faster so I'm wondering is there a way to make it get the HTTP code without actually getting the web page from the remote host
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
CURLOPT_NOBODY
设置为 true。这意味着将执行 HEAD 请求,而不是执行 GET 或 POST 请求,因此远程服务器将仅返回 HTTP 标头。这个答案中还有一些示例代码
Set
CURLOPT_NOBODY
to true. This means that rather than preforming a GET or POST request, a HEAD request will be preformed so the remote server will only return the HTTP header.There is also some example code in this answer