limiting download size with curl

This is a discussion on limiting download size with curl within the PHP Language forums, part of the PHP Programming Forums category; Hi! I have a server I'd like to download hundreds of pages from, and only get the first few ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-26-2008
shikakaa@gmail.com
 
Posts: n/a
Default limiting download size with curl

Hi!

I have a server I'd like to download hundreds of pages from, and only
get the first few kilobytes of every page to save resources on both my
and the remote end. Since the serfver doesn't support HTTP range to
use it in curl like curl_setopt($ch, CURLOPT_RANGE, "0-5000"); I
started looking around and found that using the custom write function
I might be able to do the same.

As I understand it, closing the handle and thus terminating the
transfer from within the callback function is not possible, so I'm a
bit stuck..

How could I achieve this? Could someone paste me a fewliner example?

Thanks in advance
Andrew
Reply With Quote
  #2 (permalink)  
Old 02-26-2008
Iván Sánchez Ortega
 
Posts: n/a
Default Re: limiting download size with curl

shikakaa@gmail.com wrote:

> I have a server I'd like to download hundreds of pages from, and only
> get the first few kilobytes of every page to save resources on both my
> and the remote end.


Have you though using a HTTP HEAD request instead of a HTTP GET request?

Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

No es culpable el asesino, sino el asesinado.
Reply With Quote
  #3 (permalink)  
Old 02-26-2008
Toby A Inkster
 
Posts: n/a
Default Re: limiting download size with curl

shikakaa@gmail.com wrote:

> As I understand it, closing the handle and thus terminating the transfer
> from within the callback function is not possible, so I'm a bit stuck..
>
> How could I achieve this?


TCP Sockets. GET requests are not *that* difficult to implement.


--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 27 days, 23:43.]

Bottled Water
http://tobyinkster.co.uk/blog/2008/02/18/bottled-water/
Reply With Quote
  #4 (permalink)  
Old 02-26-2008
shikakaa@gmail.com
 
Posts: n/a
Default Re: limiting download size with curl

On Feb 26, 6:06*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.org> wrote:
> shika...@gmail.com wrote:
> > I have a server I'd like to download hundreds of pages from, and only
> > get the first few kilobytes of every page to save resources on both my
> > and the remote end.

>
> Have you though using a HTTP HEAD request instead of a HTTP GET request?
>
> Cheers,


As I understand it, the HTTP HEAD request would get me a response that
doesn't have the body of the file in question. The target of my file
downloads are about 20% into body of the file, so this approach
wouldn't work.

Thank you for the suggestion though!
Reply With Quote
  #5 (permalink)  
Old 02-26-2008
shikakaa@gmail.com
 
Posts: n/a
Default Re: limiting download size with curl

On Feb 26, 6:26*pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
> shika...@gmail.com wrote:
> > As I understand it, closing the handle and thus terminating the transfer
> > from within the callback function is not possible, so I'm a bit stuck..

>
> > How could I achieve this?

>
> TCP Sockets. GET requests are not *that* difficult to implement.


Could you please show me an example of this? I'm not sure what I'm
supposed to be googling for at this point.
Reply With Quote
  #6 (permalink)  
Old 02-27-2008
Manuel Lemos
 
Posts: n/a
Default Re: limiting download size with curl

Hello,

on 02/26/2008 04:07 PM shikakaa@gmail.com said the following:
> On Feb 26, 6:26 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
> wrote:
>> shika...@gmail.com wrote:
>>> As I understand it, closing the handle and thus terminating the transfer
>>> from within the callback function is not possible, so I'm a bit stuck..
>>> How could I achieve this?

>> TCP Sockets. GET requests are not *that* difficult to implement.

>
> Could you please show me an example of this? I'm not sure what I'm
> supposed to be googling for at this point.


You can use this HTTP client class that uses TCP sockets with the PHP
fsockopen and only retrieve the amount of data that you want. It figures
what is the response body and headers so you do not have to write
additional code to parse the headers and skip them:

http://www.phpclasses.org/httpclient


--

Regards,
Manuel Lemos

PHP professionals looking for PHP jobs
http://www.phpclasses.org/professionals/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/
Reply With Quote
  #7 (permalink)  
Old 02-27-2008
Jerry Stuckle
 
Posts: n/a
Default Re: limiting download size with curl

Manuel Lemos wrote:
> Hello,
>
> on 02/26/2008 04:07 PM shikakaa@gmail.com said the following:
>> On Feb 26, 6:26 pm, Toby A Inkster <usenet200...@tobyinkster.co.uk>
>> wrote:
>>> shika...@gmail.com wrote:
>>>> As I understand it, closing the handle and thus terminating the transfer
>>>> from within the callback function is not possible, so I'm a bit stuck..
>>>> How could I achieve this?
>>> TCP Sockets. GET requests are not *that* difficult to implement.

>> Could you please show me an example of this? I'm not sure what I'm
>> supposed to be googling for at this point.

>
> You can use this HTTP client class that uses TCP sockets with the PHP
> fsockopen and only retrieve the amount of data that you want. It figures
> what is the response body and headers so you do not have to write
> additional code to parse the headers and skip them:
>
> http://www.phpclasses.org/httpclient
>
>


Manuel,

Is the only reason you're on this newsgroup is to promote your junky
classes?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 04:06 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0