gpt4 book ai didi

php - get 的 cURL 大小限制

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:14 28 4
gpt4 key购买 nike

我想知道有没有办法通过cURL只获取特定数量的数据?

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

选项 2:
Having trouble limiting download size of PHP's cURL function但是这个函数给我错误 Failed writing body (0 != 11350) 和 reading 我发现很多人说这是一个错误。

所以按照上面的 write_function 我尝试 curl_close($handle) 而不是 returning 0 但这会引发错误 Attempt从回调中关闭 cURL 句柄

现在我能想到的唯一方法是根据内容长度解析 header 但这最终会导致 2 个请求?? 首先使用 CURLOPT_NOBODY 获取 header 然后获取完整内容?

最佳答案

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.

目前尚不清楚您到底在做什么。如果您返回 0,那么 cURL 肯定会发出错误信号,但是您已经读取了所有需要的数据。忽略错误即可。

如果您尝试过,您不会提及的另一个选项是将 fopenhttp:// 包装器一起使用。例如:

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

关于php - get 的 cURL 大小限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5464914/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com