替代 CURLOPT_RANGE 以获取特定部分 [英] Alternative to CURLOPT_RANGE to grab a specific section

查看:26
本文介绍了替代 CURLOPT_RANGE 以获取特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 curl 仅获取页面的一部分,这样它会下载更少的数据,从而使其更快.我一直在测试我能想到的所有可能的选择,但无济于事.我尝试过的主要方法是定义一个范围:curl_setopt($ch, CURLOPT_RANGE, "0-4096");

I'm trying to use curl to fetch only a portion of a page so it will download less data thus making it quicker. I've been testing every possible option i can think of to no avail. The main one ive tried is defining a range: curl_setopt($ch, CURLOPT_RANGE, "0-4096");

我尝试使用的服务器是 HTTP 1.1,但该设置在整个页面被拉出时无效.是否有另一种方法可以在 PHP 中的 X 字节或类似的内容之后关闭连接?

The servers im trying this on are HTTP 1.1 but the setting has no effect as the entire page is pulled. Is there an alternative way to close the connection after X bytes in PHP or something along those lines?

推荐答案

您可以使用自己的写回调 (CURLOPT_WRITEFUNCTION) 并在收到足够的数据后让它返回错误.

You can use your own write callback (CURLOPT_WRITEFUNCTION) and have that return an error once you've received enough data.

可以在此处找到使用此类写入回调的示例:http://curl.haxx.se/libcurl/php/examples/callbacks.html

An example using such a write callback can be found here: http://curl.haxx.se/libcurl/php/examples/callbacks.html

这篇关于替代 CURLOPT_RANGE 以获取特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆