$^T is not working as expected from mod_perl

Discussion in 'Perl Misc' started by Patrick Hartman, Feb 18, 2010.

  1. I was using this to calculate execution time at the bottom of a
    script:

    print time - $^T;

    However I noticed that the time just got a little bit longer everytime
    I ran it despite the apparent page load time not changing at all. I
    changed it to this:

    printf "BEG: $^T \n";
    printf "END: ". time;

    And the $^T was outputting the same start time for every execution;
    every time I would load the page, the time just got longer and longer
    since only the end time was updating.

    This problem is only happening when I execute from mod_perl / Apache.
    If I go to the command line and execute it through there it works
    fine. I have Apache on my local computer, so both places are pointing
    to the same installation of Perl.

    Any ideas what would be causing this?

    Thanks,
    Patrick
     
    Patrick Hartman, Feb 18, 2010
    #1
    1. Advertising

  2. On Feb 17, 7:53 pm, Patrick Hartman <> wrote:
    > I was using this to calculate execution time at the bottom of a
    > script:
    >
    > print time - $^T;
    >
    > However I noticed that the time just got a little bit longer everytime
    > I ran it despite the apparent page load time not changing at all. I
    > changed it to this:
    >
    > printf "BEG: $^T \n";
    > printf "END: ". time;
    >
    > And the $^T was outputting the same start time for every execution;
    > every time I would load the page, the time just got longer and longer
    > since only the end time was updating.
    >
    > This problem is only happening when I execute from mod_perl / Apache.
    > If I go to the command line and execute it through there it works
    > fine. I have Apache on my local computer, so both places are pointing
    > to the same installation of Perl.
    >
    > Any ideas what would be causing this?
    >
    > Thanks,
    > Patrick


    Sorry, I should have searched Google first. I will post the solution I
    found and beg for forgiveness :).

    http://modperlbook.org/html/6-5-1-T-and-time.html

    "Under mod_perl, processes don't quit after serving a single request.
    Thus, $^T gets initialized to the server startup time and retains this
    value throughout the process's life. Even if you don't use this
    variable directly, it's important to know that Perl refers to the
    value of $^T internally."

    Patrick
     
    Patrick Hartman, Feb 18, 2010
    #2
    1. Advertising

  3. On Wed, 17 Feb 2010 17:53:41 -0800, Patrick Hartman wrote:

    > I was using this to calculate execution time at the bottom of a script:
    >
    > print time - $^T;
    >
    > However I noticed that the time just got a little bit longer everytime I
    > ran it despite the apparent page load time not changing at all. I
    > changed it to this:
    >
    > printf "BEG: $^T \n";
    > printf "END: ". time;
    >
    > And the $^T was outputting the same start time for every execution;
    > every time I would load the page, the time just got longer and longer
    > since only the end time was updating.
    >
    > This problem is only happening when I execute from mod_perl / Apache. If
    > I go to the command line and execute it through there it works fine. I
    > have Apache on my local computer, so both places are pointing to the
    > same installation of Perl.
    >
    > Any ideas what would be causing this?
    >


    Mod_perl loads the interpreter only once. Just store the start time at
    the top of your script and use that instead of ^T.

    M4
     
    Martijn Lievaart, Feb 18, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard Huff
    Replies:
    2
    Views:
    407
    Richard Huff
    Jan 6, 2004
  2. Natty Gur
    Replies:
    1
    Views:
    1,907
    Marshal Antony
    Mar 3, 2004
  3. =?Utf-8?B?amFtbWVy?=

    Validation not working as expected

    =?Utf-8?B?amFtbWVy?=, Aug 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    =?Utf-8?B?amFtbWVy?=
    Aug 19, 2005
  4. Steve Franks

    Cache not working as expected

    Steve Franks, Sep 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    471
    Jeremy S.
    Sep 11, 2005
  5. Replies:
    2
    Views:
    463
    Big and Blue
    Jan 25, 2006
Loading...

Share This Page