Re: limiting transferred data using curl

This is a discussion on Re: limiting transferred data using curl within the PHP Language forums, part of the PHP Programming Forums category; Hi, You can terminate the download in your WRITEFUNCTION callback by returning 0. Here's an example: <? error_reporting(E_ALL | ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008
petersprc
 
Posts: n/a
Default Re: limiting transferred data using curl

Hi,

You can terminate the download in your WRITEFUNCTION callback by
returning 0. Here's an example:

<?

error_reporting(E_ALL | E_STRICT);

// This class encapsulates the callback functions

class curlHandler
{
var $data;
var $readCount = 0;
var $maxRead = 20000;

function writeProc($ch, $str)
{
$len = strlen($str);
$n = min($this->maxRead - $this->readCount, $len);
$this->data .= substr($str, 0, $n);
$this->readCount += $n;
echo "Read {$this->readCount} bytes (max {$this->maxRead}).<br>
\n";
if ($this->readCount >= $this->maxRead) {
return 0;
}
return $len;
}
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.php.net');
$cp = new curlHandler;
curl_setopt($ch, CURLOPT_WRITEFUNCTION, array(&$cp, 'writeProc'));
curl_exec($ch);
echo "<br>\nGot " . strlen($cp->data) . " bytes.<br><br>\n\n";

echo "CURL statistics:<br><br>\n\n";
$info = curl_getinfo($ch);
var_dump($info);
curl_close($ch);

?>

Regards,

John Peters

On Feb 26, 11:54 am, "shika...@gmail.com" <shika...@gmail.com> wrote:
> 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 server 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 get this done? Could someone paste me a fewliner example?
>
> Thanks in advance
> Andrew


Reply With Quote
  #2 (permalink)  
Old 02-28-2008
Captain Paralytic
 
Posts: n/a
Default Re: limiting transferred data using curl

On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
> Hi,


Hey John,
which part of "Please do not top post" is it that you are having
trouble understanding?

Reply With Quote
  #3 (permalink)  
Old 02-28-2008
esaniah@gmail.com
 
Posts: n/a
Default [OT] Re: limiting transferred data using curl

Captain Paralytic,

If you *MUST* make an off topic post, please preface the subject with
"[OT]", so those who are not interested in OT posts can skip them.

On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
>
> > Hi,

>
> Hey John,
> which part of "Please do not top post" is it that you are having
> trouble understanding?


Reply With Quote
  #4 (permalink)  
Old 02-28-2008
Jerry Stuckle
 
Posts: n/a
Default Re: [OT] Re: limiting transferred data using curl

esaniah@gmail.com wrote:
> On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
>>
>>> Hi,

>> Hey John,
>> which part of "Please do not top post" is it that you are having
>> trouble understanding?

>
>
> Captain Paralytic,
>
> If you *MUST* make an off topic post, please preface the subject with
> "[OT]", so those who are not interested in OT posts can skip them.
>


(Top posting fixed)

It is not off topic in this newsgroup to ask people to not top post.
Intertwined or bottom posting is the norm for this newsgroup.

Please don't top post!

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

Reply With Quote
  #5 (permalink)  
Old 02-28-2008
Jerry Stuckle
 
Posts: n/a
Default Re: limiting transferred data using curl

esaniah@gmail.com wrote:
> On Feb 28, 9:19 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> esan...@gmail.com wrote:
>>> On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>>>> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
>>>>> Hi,
>>>> Hey John,
>>>> which part of "Please do not top post" is it that you are having
>>>> trouble understanding?
>> > Captain Paralytic,
>> >
>> > If you *MUST* make an off topic post, please preface the subject with
>> > "[OT]", so those who are not interested in OT posts can skip them.
>> >

>>
>> (Top posting fixed)
>>
>> It is not off topic in this newsgroup to ask people to not top post.
>> Intertwined or bottom posting is the norm for this newsgroup.
>>
>> Please don't top post!
>>

> Jerry,
>
> You're completely misrepresenting the newsgroup's charter.
>
> "comp.lang.php is intended to be a global forum for the discussion of
> issues involving PHP ... Since database connectivity is a large part
> of PHP, it will be considered topical in comp.lang.php."
>
> PHP and databases are on-topic. Posting styles are not. How hard is it
> to use [OT] like everyone else?
>


(Top posting fixed again)

Because suggesting people follow the norms for this newsgroup is within
the bounds of the newsgroup. Period.

You can keep top posting if you want - but don't expect to get much help
from this newsgroups.

A. Because they are either idiots or assholes.
Q. Why do people continue to top post?
A. We politely let them know the correct way to post.
Q. What do you do about it?
A. Because they don't know any better.
Q. Why do people top post?
A. Because it interrupts the normal flow of the messages.
Q. Why is it so annoying?
A. Top posting.
Q. What's the most annoying thing on usenet?

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

Reply With Quote
  #6 (permalink)  
Old 02-28-2008
esaniah@gmail.com
 
Posts: n/a
Default [OT] Re: limiting transferred data using curl

Jerry,

You're completely misrepresenting the newsgroup's charter.

"comp.lang.php is intended to be a global forum for the discussion of
issues involving PHP ... Since database connectivity is a large part
of PHP, it will be considered topical in comp.lang.php."

PHP and databases are on-topic. Posting styles are not. How hard is it
to use [OT] like everyone else?

On Feb 28, 9:19 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> esan...@gmail.com wrote:
> > On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> >> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:

>
> >>> Hi,
> >> Hey John,
> >> which part of "Please do not top post" is it that you are having
> >> trouble understanding?

>
> > Captain Paralytic,
> >
> > If you *MUST* make an off topic post, please preface the subject with
> > "[OT]", so those who are not interested in OT posts can skip them.
> >

>
> (Top posting fixed)
>
> It is not off topic in this newsgroup to ask people to not top post.
> Intertwined or bottom posting is the norm for this newsgroup.
>
> Please don't top post!
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Reply With Quote
  #7 (permalink)  
Old 02-28-2008
Michael Fesser
 
Posts: n/a
Default Re: [OT] Re: limiting transferred data using curl

..oO(esaniah@gmail.com)

>You're completely misrepresenting the newsgroup's charter.
>
>"comp.lang.php is intended to be a global forum for the discussion of
>issues involving PHP ... Since database connectivity is a large part
>of PHP, it will be considered topical in comp.lang.php."
>
>PHP and databases are on-topic. Posting styles are not. How hard is it
>to use [OT] like everyone else?


It's even easier to ignore people like you who don't want to respect
even the most basic rules in a community to make it as easy as possible
for the members of that community to offer their help for free.

You shouldn't bite the hand that feeds you.

Micha
Reply With Quote
  #8 (permalink)  
Old 02-29-2008
esaniah@gmail.com
 
Posts: n/a
Default [OT] Re: limiting transferred data using curl

Jerry,

Whining about posting styles is not and has never been on topic for
this newsgroup. If you are interested in improving the single-to-noise
ratio in this group, you will follow the same standards that everyone
else does and use "[OT]" when discussing topics unrelated to PHP and
databases.

If you wish to continue posting off-topic content without warning
folks, that's a quick way to get yourself kill-filed by a large number
of readers.

On Feb 28, 10:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> esan...@gmail.com wrote:
> > On Feb 28, 9:19 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> >> esan...@gmail.com wrote:
> >>> On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> >>>> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
> >>>>> Hi,
> >>>> Hey John,
> >>>> which part of "Please do not top post" is it that you are having
> >>>> trouble understanding?
> >> > Captain Paralytic,

>
> >> > If you *MUST* make an off topic post, please preface the subject with
> >> > "[OT]", so those who are not interested in OT posts can skip them.

>
> >> (Top posting fixed)

>
> >> It is not off topic in this newsgroup to ask people to not top post.
> >> Intertwined or bottom posting is the norm for this newsgroup.

>
> >> Please don't top post!

>
> > Jerry,
> >
> > You're completely misrepresenting the newsgroup's charter.
> >
> > "comp.lang.php is intended to be a global forum for the discussion of
> > issues involving PHP ... Since database connectivity is a large part
> > of PHP, it will be considered topical in comp.lang.php."
> >
> > PHP and databases are on-topic. Posting styles are not. How hard is it
> > to use [OT] like everyone else?
> >

>
> (Top posting fixed again)
>
> Because suggesting people follow the norms for this newsgroup is within
> the bounds of the newsgroup. Period.
>
> You can keep top posting if you want - but don't expect to get much help
> from this newsgroups.
>
> A. Because they are either idiots or assholes.
> Q. Why do people continue to top post?
> A. We politely let them know the correct way to post.
> Q. What do you do about it?
> A. Because they don't know any better.
> Q. Why do people top post?
> A. Because it interrupts the normal flow of the messages.
> Q. Why is it so annoying?
> A. Top posting.
> Q. What's the most annoying thing on usenet?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================


Reply With Quote
  #9 (permalink)  
Old 02-29-2008
Jerry Stuckle
 
Posts: n/a
Default Re: limiting transferred data using curl

esaniah@gmail.com wrote:
> On Feb 28, 10:42 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> esan...@gmail.com wrote:
>>> On Feb 28, 9:19 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>>>> esan...@gmail.com wrote:
>>>>> On Feb 28, 8:09 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>>>>>> On 28 Feb, 14:04, petersprc <peters...@gmail.com> wrote:
>>>>>>> Hi,
>>>>>> Hey John,
>>>>>> which part of "Please do not top post" is it that you are having
>>>>>> trouble understanding?
>>>> > Captain Paralytic,
>>>> > If you *MUST* make an off topic post, please preface the subject with
>>>> > "[OT]", so those who are not interested in OT posts can skip them.
>>>> (Top posting fixed)
>>>> It is not off topic in this newsgroup to ask people to not top post.
>>>> Intertwined or bottom posting is the norm for this newsgroup.
>>>> Please don't top post!
>> > Jerry,
>> >
>> > You're completely misrepresenting the newsgroup's charter.
>> >
>> > "comp.lang.php is intended to be a global forum for the discussion of
>> > issues involving PHP ... Since database connectivity is a large part
>> > of PHP, it will be considered topical in comp.lang.php."
>> >
>> > PHP and databases are on-topic. Posting styles are not. How hard is it
>> > to use [OT] like everyone else?
>> >

>>
>> (Top posting fixed again)
>>
>> Because suggesting people follow the norms for this newsgroup is within
>> the bounds of the newsgroup. Period.
>>
>> You can keep top posting if you want - but don't expect to get much help
>> from this newsgroups.
>>
>> A. Because they are either idiots or assholes.
>> Q. Why do people continue to top post?
>> A. We politely let them know the correct way to post.
>> Q. What do you do about it?
>> A. Because they don't know any better.
>> Q. Why do people top post?
>> A. Because it interrupts the normal flow of the messages.
>> Q. Why is it so annoying?
>> A. Top posting.
>> Q. What's the most annoying thing on usenet?
>>

> Jerry,
>
> Whining about posting styles is not and has never been on topic for
> this newsgroup. If you are interested in improving the single-to-noise
> ratio in this group, you will follow the same standards that everyone
> else does and use "[OT]" when discussing topics unrelated to PHP and
> databases.
>
> If you wish to continue posting off-topic content without warning
> folks, that's a quick way to get yourself kill-filed by a large number
> of readers.
>


(Top posting fixed)

No, you're just showing what an ass you are by continuing to top post.
Go ahead and plonk me if you want. I'm sure a lot of other regulars in
this group have already *plonked you*.

But that's what happens when you get a troll coming in through google
groups.

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

Reply With Quote
  #10 (permalink)  
Old 02-29-2008
Ivan Marsh
 
Posts: n/a
Default Re: [OT] Re: limiting transferred data using curl

On Fri, 29 Feb 2008 10:22:55 -0800, esaniah wrote:

> Jerry,
>
> Whining about posting styles is not and has never been on topic for this
> newsgroup. If you are interested in improving the single-to-noise ratio
> in this group, you will follow the same standards that everyone else
> does and use "[OT]" when discussing topics unrelated to PHP and
> databases.


You couldn't be more wrong. By top posting you have turned the thread into
a thread about top posting.

Please don't top post.

--
I told you this was going to happen.

Reply With Quote
Reply


Thread Tools
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

vB 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 11:02 PM.


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