PHP Curl获取HTTP代码,而不是整个文档 [英] PHP Curl get HTTP code, not whole document

查看:121
本文介绍了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

推荐答案

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.

curl_setopt($ch, CURLOPT_NOBODY, true);

此答案中也有一些示例代码

There is also some example code in this answer

这篇关于PHP Curl获取HTTP代码,而不是整个文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆