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

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
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)

In reply to RE: Apache Timeout module by plaid
in thread Apache Timeout module by jjhorner

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (8)
    As of 2015-07-07 00:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (85 votes), past polls