![]() |
Limiting the number of KBs per fetch?
I'm using cURL to fetch archive.org search results, some pages are above 500kb that increases the page loading time, I want to limit the size of the page to fetch i.e to around 20-50kbs.
|
From my experience, I would be inclined to say no out right because of the way the TCP protocol suite works. Although large web-pages will be returned to you via multiple packets, the TCP suite would expect them to be returned no matter what. If packets aren't received it'll just send them again, and I'm not sure cURL would have the power to terminate the session half-way through.
|
There is a cURL option called
CURLOPT_RANGE whose value (in bytes) can be:Range(s) of data to retrieve in the format "X-Y" where X or Y are optional. HTTP transfers also support several intervals, separated with commas in the format "X-Y,N-M".That might be of use to you. |
Quote:
|
From experimenting, it seems to work on some sites but not others. My guess is that some sites respect the HTTP_Range header being sent, and other don't.
Another option would be to fopen/fread the required amount. |
This can still be done using cURL however it is a bit of a pain, you can use the built-in callback functions to do the work storing the content and sending false when reached the required amount.
Salathe's suggestion will work when a website sends the correct http 1.1 headers that include the byte range acceptance header. A snippet from a class i created a while back to work with this: PHP Code:
|
| All times are GMT. The time now is 05:40 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0