cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: can't get curl dns cache to work

From: Phillip Stevens <pj2k_at_hotmail.com>
Date: Fri, 05 Apr 2002 17:23:47 +1000

> > eg.. If I repeatedly request 'domain.com' once every 7 seconds and kill
>the
> > dns during the process, after 60 seconds the requests will fail (as
> > expected). However, if I change the page request interval from 7 to 5
> > seconds, the cache never times out.
>
>Just being careful here, you aren't by any chance using persistant
>connections here so that when you use short intervals the previous
>connection
>is still alive and simply re-used?

I'm using the same curl session, simply changing the CURLOPT_URL and then
using 'perform' to retrieve the file. Never running cleanup until the end of
program. I also tried alternating between two domains, hoping this would
kill any live connections?

I don't really need to use this cache timeout option anyway, just thought
I'd let you know.

thanks.

for your interest, see the following..

the code below doesn't seem to timeout if you kill the dns during the
process, however if you increase the sleep command it will start to time out
-

use strict;
use Curl::easy;

my $curl= Curl::easy::init();
if(!$curl) {
    die "curl init failed!\n";
}

Curl::easy::setopt($curl, CURLOPT_DNS_CACHE_TIMEOUT, 0); #no cache

$::errbuf="";
Curl::easy::setopt($curl, CURLOPT_ERRORBUFFER, "::errbuf");

my $count;
my $count2;
my $url;

while ($count<100){ #perform 100 requests
$count++;

$count2++;
if ($count2 == 1){ #alternate between two domains
        $url = "http://domaintest1.com";
}
else{
        $url = "http://domaintest2.com";
        $count2=0;
}

Curl::easy::setopt($curl, CURLOPT_URL, $url);

sub body_callback {
    my ($chunk,$handle)=@_;
    push @$handle, $chunk;
    return length($chunk); # OK
}
Curl::easy::setopt($curl, CURLOPT_WRITEFUNCTION, \&body_callback);

my @body;

Curl::easy::setopt($curl, CURLOPT_FILE, \@body);

if (Curl::easy::perform($curl) != 0) {
    print "Failed :$::errbuf\n";
};

my $html;
$html = join("",@body);

sleep 1;
};

# Cleanup
Curl::easy::cleanup($curl);

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
Received on 2002-04-05