PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > limiting transferred data using curl
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
limiting transferred data using curl

Réponse
 
LinkBack Outils de la discussion
Vieux 26/02/2008, 17h54   #1
shikakaa@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut limiting transferred data using 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 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
  Réponse avec citation
Vieux 28/02/2008, 15h04   #2
petersprc
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


  Réponse avec citation
Vieux 28/02/2008, 15h09   #3
Captain Paralytic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?

  Réponse avec citation
Vieux 28/02/2008, 15h59   #4
esaniah@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [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?


  Réponse avec citation
Vieux 28/02/2008, 16h19   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
==================

  Réponse avec citation
Vieux 28/02/2008, 17h42   #6
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
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
==================

  Réponse avec citation
Vieux 28/02/2008, 17h51   #7
esaniah@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [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
> ==================


  Réponse avec citation
Vieux 29/02/2008, 19h22   #8
esaniah@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [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
> 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
> ==================


  Réponse avec citation
Vieux 29/02/2008, 19h25   #9
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
>> 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
==================

  Réponse avec citation
Vieux 02/03/2008, 00h13   #10
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [OT] Re: limiting transferred data using curl

You're doing nothing other than spamming comp.lang.php.

If you feel the need to make off-topic comments, put [OT] in the subject like the previous poster already
told you to do, so that the rest of us can skip this junk. It's basic netiquette.

Take it to a more appropriate forum please.

--
Tom Stewart, ATC


> (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.
>

  Réponse avec citation
Vieux 02/03/2008, 00h14   #11
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

You don't undesrtand the purpose of this newsgroup which is to discuss PHP and not your favorite posting
style.

Stay on topic please.

--
Tom Stewart, ATC

Ivan Marsh <annoyed@you.now> wrote:
> 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.
>

  Réponse avec citation
Vieux 02/03/2008, 01h09   #12
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

Jerry is a key contributor to this newsgroup and his
posts are filled with valuable insights.

However, his contribution to this thread is spam and
goes against comp.lang.php's charter.

You're capable of a lot better, Jerry.

--
Tom Stewart, ATC


Tom Stewart <tichini@gmail.com> wrote:
> You're doing nothing other than spamming comp.lang.php.
>
> If you feel the need to make off-topic comments, put [OT] in the subject like the previous poster already
> told you to do, so that the rest of us can skip this junk. It's basic netiquette.
>
> Take it to a more appropriate forum please.
>
>>
>> (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.

  Réponse avec citation
Vieux 02/03/2008, 02h56   #13
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

Tom Stewart wrote:
> You're doing nothing other than spamming comp.lang.php.
>
> If you feel the need to make off-topic comments, put [OT] in the subject like the previous poster already
> told you to do, so that the rest of us can skip this junk. It's basic netiquette.
>
> Take it to a more appropriate forum please.
>


Bullshit. I'm doing nothing more than calling you what you are - an
asshole.

You come in here new and try to tell all the regulars what's off topic?

You really are an ass. Do us all a favor. Crawl back into your hole
and get lost.

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

  Réponse avec citation
Vieux 02/03/2008, 02h57   #14
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: limiting transferred data using curl

Tom Stewart wrote:
> Jerry is a key contributor to this newsgroup and his
> posts are filled with valuable insights.
>
> However, his contribution to this thread is spam and
> goes against comp.lang.php's charter.
>
> You're capable of a lot better, Jerry.
>


No, you're just an asshole.

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

  Réponse avec citation
Vieux 02/03/2008, 04h40   #15
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: limiting transferred data using curl

Tom Stewart wrote:
> Your opinion in this thread doesn't count for much.
>


It count for a lot more than a top posting asshole.

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

  Réponse avec citation
Vieux 02/03/2008, 04h40   #16
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

Tom Stewart wrote:
> You lost credibility in this thread when you resorted
> to ad-hominem attacks instead of simply following the
> established rules like everyone else.
>
> All you've proven is that you're intent on being a
> disruption.
>


No, you lost credibility when you started top posting and made an ass of
yourself when people tried to gently correct you.

Sorry, you're the idiot here. As you continue to prove.

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

  Réponse avec citation
Vieux 02/03/2008, 04h59   #17
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

You lost credibility in this thread when you resorted
to ad-hominem attacks instead of simply following the
established rules like everyone else.

All you've proven is that you're intent on being a
disruption.

--
Tom Stewart, ATC


Jerry Stuckle <jstucklex@attglobal.net> wrote:
> Tom Stewart wrote:
>> You're doing nothing other than spamming comp.lang.php.
>>
>> If you feel the need to make off-topic comments, put [OT] in the subject like the previous poster already
>> told you to do, so that the rest of us can skip this junk. It's basic netiquette.
>>
>> Take it to a more appropriate forum please.
>>

>
> Bullshit. I'm doing nothing more than calling you what you are - an
> asshole.
>
> You come in here new and try to tell all the regulars what's off topic?
>
> You really are an ass. Do us all a favor. Crawl back into your hole
> and get lost.
>

  Réponse avec citation
Vieux 02/03/2008, 05h00   #18
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: limiting transferred data using curl

Your opinion in this thread doesn't count for much.

--
Tom Stewart, ATC


Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
> No, you're just an asshole.
>

  Réponse avec citation
Vieux 02/03/2008, 05h51   #19
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

You've sent at lease 10 pieces of spam just in this
one thread.

You can continue denying and resisting the rules,
but you're only digging yourself into a deeper hole.

Try studying this:

http://en.wikipedia.org/wiki/Off-topic

"Internet trolls will sometimes post off topic messages
deliberately on internet forums to aggravate members or
hijack a discussion."

And read the charter, if you can find it.

--
Tom Stewart, ATC


Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
> No, you lost credibility when you started top posting and made an ass of
> yourself when people tried to gently correct you.
>
> Sorry, you're the idiot here. As you continue to prove.
>

  Réponse avec citation
Vieux 02/03/2008, 05h52   #20
Tom Stewart
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [OT] Re: limiting transferred data using curl

You mean "counts." You're sorely mistaken if you
think a spammer's opinion has any merit here.

Jerry Stuckle <jstucklex@attglobal.net> wrote:
>
> It count for a lot more than a top posting asshole.
>

  Réponse avec citation
Vieux 10/03/2008, 01h50   #21
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

Tom Stewart <tichini@gmail.com> wrote:
> You don't undesrtand the purpose of this newsgroup
> which is to discuss PHP and not your favorite posting
> style.
>
> Stay on topic please.
>


Posting off-topic is fine. I don't care. Usenet is an
open place that fosters open discussion.

Not that I'm saying you were even off-topic, which you
were not.

--
Tom Stewart, ATC
  Réponse avec citation
Vieux 10/03/2008, 01h54   #22
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [OT] Re: limiting transferred data using curl

Tom Stewart <tichini@gmail.com> wrote:
> You've sent at lease 10 pieces of spam just in this
> one thread.


I didn't mean to suggest Jerry is in any way spamming..
That's just not true at all.

--
Tom Stewart, ATC
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h39.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,32145 seconds with 30 queries