[英]How to send an incomplete HTTP request from PHP?
I need to check if remote file are online and they didn't change. 我需要检查远程文件是否在线并且它们没有更改。 The problem is that those files are big, so I want to read the http header only and then abort the request.
问题是这些文件很大,所以我只想读取http标头,然后中止请求。 The result would be based on response status code and content length field.
结果将基于响应状态代码和内容长度字段。
How can I do it in PHP? 如何在PHP中做到这一点?
You can use the get_headers()
function. 您可以使用
get_headers()
函数。
If you prefer cURL , you can use CURLOPT_NOBODY
: 如果您更喜欢cURL ,则可以使用
CURLOPT_NOBODY
:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$headers = curl_exec($ch);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.