PHP Curl 获取 HTTP 代码,而不是整个文档

发布于 2024-08-29 04:06:29 字数 87 浏览 2 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏闹i 2024-09-05 04:06:38

CURLOPT_NOBODY 设置为 true。这意味着将执行 HEAD 请求,而不是执行 GET 或 POST 请求,因此远程服务器将仅返回 HTTP 标头。

curl_setopt($ch, CURLOPT_NOBODY, true);

这个答案中还有一些示例代码

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文