Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

RE: Apache Timeout module

by plaid (Chaplain)
on Jun 09, 2000 at 23:49 UTC ( #17418=note: print w/ replies, xml ) Need Help??


in reply to Apache Timeout module

First thing, the way you have it set up to check timestamps, the line if ($time_to_die >= ($current_time - $last_time)) { seems to suggest that $time_to_die is in seconds, as both $current_time and $last_time are in seconds, but I believe you were expecting $time_to_die in minutes, so you may want to throw a *= 60 in there or something.

One thing I was considering about this is that there isn't really a need to throw the timestamp into a file, since basically you're just storing the exact same number as is already contained in the file's modification time. Since you're already effectively performing a stat via the -e test, you can then just use the cached filehandle _ to obtain the modification time and cut out an additional file opening/reading/writing.

use Benchmark; use strict; my $time_to_die = 15; my $time_file_1 = "time1.txt"; my $time_file_2 = "time2.txt"; my $current_time = time(); # kept this outside the benchmark timethese(100000, { 'Time In File' => \&timeinfile, 'File Mod Time' => \&filemodtime }); sub timeinfile { if (-e $time_file_1) { open (TIME, "$time_file_1") || warn "Can't open Time file: $!"; my $last_time = <TIME> || warn "Unable to get timestamp from fil +e: $!"; close TIME; if ($time_to_die >= ($current_time - $last_time)) { open (TIME, ">$time_file_1"); print TIME $current_time || warn "Unable to write timestamp t +o file: $!"; close TIME; } else { unlink($time_file_1) or warn "Can't unlink file: $!"; } } else { open (TIME, ">$time_file_1"); print TIME $current_time; close TIME; } } sub filemodtime { if(-e $time_file_2) { my $last_time = (stat(_))[9]; if($time_to_die >= ($current_time - $last_time)) { open (TIME, ">$time_file_2"); close TIME; } else { unlink($time_file_2) or warn "Can't unlink file: $!"; } } else { open (TIME, ">$time_file_2"); close TIME; } } Benchmark: timing 100000 iterations of File Mod Time, Time In File... File Mod Time: 11 wallclock secs ( 6.97 usr + 3.21 sys = 10.18 CPU) Time In File: 48 wallclock secs (21.26 usr + 25.77 sys = 47.03 CPU)


Comment on RE: Apache Timeout module
Download Code
RE: RE: Apache Timeout module
by jjhorner (Hermit) on Jun 10, 2000 at 03:48 UTC

    I'm glad someone is checking my code! I like your mod time idea, and it seems to work.

    As for the TimeLimit, it will be in seconds, and I was using 15 just so debugging would go faster. Normally, it would be something like 900.

    Again, thanks for checking on my work. I really appreciate the feedback. If it is ever released to CPAN, look for your name in the README.

    J. J. Horner
    Linux, Perl, Apache, Stronghold, Unix
    jhorner@knoxlug.org http://www.knoxlug.org/
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://17418]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2014-07-11 18:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (234 votes), past polls