get的cURL大小限制(cURL size limit of get)

编程入门 行业动态 更新时间:2024-10-22 14:30:09
get的cURL大小限制(cURL size limit of get)

我想知道是否有任何方法通过cURL获取特定数量的数据?

选项1: curl_setopt ($curl_handle, CURLOPT_HTTPHEADER, array("Range: bytes=0-1000")); 但它不受所有服务器支持

选项2: 无法限制PHP的cURL函数的下载大小,但是这个函数给了我错误Failed writing body (0 != 11350)和阅读,我发现很多人都说它是一个错误。

所以,在上面的write_function我尝试curl_close($handle)而不是returning 0但是这会引发一个错误Attempt to close cURL handle from a callback

现在我能想到的唯一方法是解析标头的内容长度, but this will eventually result in 2 requests ?? 首先使用CURLOPT_NOBODY获取标题,然后获取完整内容?

I want to know if there is any way to get only a particular amount of data through cURL?

Option 1: curl_setopt ($curl_handle, CURLOPT_HTTPHEADER, array("Range: bytes=0-1000")); but Its not supported by all servers

Option 2: Having trouble limiting download size of PHP's cURL function but this function is giving me error Failed writing body (0 != 11350) and reading for which I found that many say its a bug.

So following the above write_function I tried to curl_close($handle) instead of returning 0 but this throws an error Attempt to close cURL handle from a callback

Now the only way I can think of is parsing headers for content length but this will eventually result in 2 requests ?? first getting headers with CURLOPT_NOBODY then getting full content?

最满意答案

选项2:无法限制PHP的cURL函数的下载大小,但此函数给我错误写入正文(0!= 11350)失败,并且我发现很多人都说它是一个错误。

目前还不清楚你到底在做什么。 如果你返回0,那么cURL会发出一个错误信号,但你必须读取所有你需要的数据。 只要忽略错误。

另一个你没有提到的选项是如果你尝试过使用http:// wrapper的fopen 。 例如:

$h = fopen('http://example.com/file.php', 'r'); $first1000Bytes = fread($h, 1000); fclose($h);

Option 2: Having trouble limiting download size of PHP's cURL function but this function is giving me error Failed writing body (0 != 11350) and reading for which I found that many say its a bug.

It's not clear what you are doing there exactly. If you return 0 then cURL will signal an error, sure, but you will have read all the data you need. Just ignore the error.

Another option that you don't mention if you have tried is to use fopen with the http:// wrapper. For example:

$h = fopen('http://example.com/file.php', 'r'); $first1000Bytes = fread($h, 1000); fclose($h);

更多推荐

本文发布于:2023-08-05 10:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1431199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小   cURL   limit   size

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!