我想知道是否有任何方法通过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);更多推荐
发布评论