Can anybody offer guidance so i can understand something about mod_perl? I put this example together in hopes that it would illustrate where i'm fuzzy about mod_perl, modules and consistent memory. Here's some background. Modules are brand new to me, i have only written a few in local testing. Mod_perl has been on my server for roughly 12 hours. It has been successfully tested. $ENV{'MOD_PERL'} returns (mod_perl/1.23). And a few benchmarks have made me smile.

I want to explore the abilities of mod_perl and sharing. Under mod_perl, i wanted to call ModCounter::TotalRun and return a incremental number which would represent the number of times that call was made. Without mod_perl, my ModCounter::TotalRun always returns 1. I expected that.
With mod_perl, i get a one digit number that changes randomly (random = "jameshasnoclue"). I read about this in the mod_perl documentation. And it explained how to stop the randomness from occuring and bring the result back to a consistent 1.

But i want the opposite. I want the counter to grow every time ModCounter::TotalRun is called. I was hoping that i could then connect several perl scripts on my server to ModCounter.pm. Each script could call the module ModCounter::TotalRun numerous times and increment the counter.

Here's the attempted module: ModCounter.pm
package ModCounter; use Exporter; @ISA = qw(Exporter); use vars qw($cnt); @EXPORT_OK = qw(TotalRun); sub TotalRun{ $cnt++; return $cnt; } 1;
And here's the script which calls ModCounter.pm.
#!/usr/bin/perl -w use strict; print "Content-type:text/html\n\n"; use ModCounter; print "cnt=".ModCounter::TotalRun; exit;

I was hoping to get an incremental count when it runs in mod_perl. Thanks for monkin.
jtrue

In reply to Persistent memory with mod_perl and a module. by true

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, 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.