mooseboy has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Was just playing around with some of the code in Sean M Burke's Perl and LWP (nice book, BTW) and encountered some unexpected behaviour with one of the examples from chapter three which uses $response->current_age(). Here's the program:
#!/usr/bin/perl use warnings; use strict; use LWP; my $browser = LWP::UserAgent->new(); my $response = $browser->get('http://www.perl.com/images/tabs/tab-perl +blk.gif', ':content_cb' => \&hex_dump, ':read_size_hint' => 123, ); print "Waiting a bit...\n"; sleep 10; my $age = $response->current_age(); print "$age\n"; # debug my $days = int($age/86400); $age -= $days * 86400; my $hours = int($age/3600); $age -= $hours * 3600; my $mins = int($age/60); $age -= $mins * 60; my $secs = $age; print "The document is $days days, $hours hours, $mins minutes, and $s +ecs seconds old.\n"; sub hex_dump { my ($data, $response) = @_; print length($data), " bytes:\n"; print ' ', unpack('H*', substr($data,0,16,'')), "\n" while length $data; return; }
On my machine (SuSE Linux 8.0, Perl 5.6.1, LWP 5.66), this program outputs "The document is 0 days, 8 hours, 57 minutes, and 28 seconds old."
But according to the HTTP::Response man page, $response->current_age
calculates the "current age" of the response as specified by draft-ietf-http-v11-spec-07 section 13.2.3. The age of a response is the time since it was sent by the origin server. The returned value is a number representing the age in seconds.
I'm puzzled as to why this program does not say the document is 10 seconds old. The only thing I can think of is that the "current age" of the document (about 9 hrs) is roughly the same as the time difference between my location (Austria) and O'Reilly in CA. Could that be the reason, or is it something else entirely?
Thanks in advance, mooseboy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $response->current_age() behaving unexpectedly
by pg (Canon) on Dec 21, 2002 at 17:21 UTC | |
by mooseboy (Pilgrim) on Dec 22, 2002 at 10:48 UTC |