ozzy has asked for the wisdom of the Perl Monks concerning the following question:

I have written a simple SSI counter, the problem is that it works fine when I run it on the command line. If I run it in my .shtml file it does not increment the counter everytime I reload the page. I tried to display the results of the counter by displaying it straight to the STDOUT
<!--#exec cmd="perl num.pl -f num.dat -i ./images" -->.

I have also tried to display the output to an .html file and then displaying the file
<!--#include file="num.html" --> which works just fine, but the counter does not get incremented on reloading the page.

SSI includes are enabled on the server. Counter Code .

Thx. Ozzy

Replies are listed 'Best First'.
Re: SSI PERL wisdom needed
by larryl (Monk) on Mar 11, 2001 at 04:54 UTC

    You might want to take a look at File::CounterFile by Gisle Aas which keeps file-based counters like yours. It uses file locking to handle multiple processes trying to modify the file at the same time, which will be an issue for you because you could have multiple simultaneous HTTP requests going on.

    It's very easy to use. This will open the file, increment the value, and return you the updated value:

    use File::CounterFile; $c = new File::CounterFile $data_file, $initial_value; $raw_data = $c->inc;

Re: SSI PERL wisdom needed
by rrwo (Friar) on Mar 11, 2001 at 03:24 UTC

    A few issues:

    1. <acronym title="Service Side Includes">SSIs</acronym> with "exec" enabled can be dangerous, especially if you (asusming it's your machine) are not the only one with the ability to create SSI documents on the web server.
    2. Does the user "nobody" (or whoever the web server runs as) have permission to modify the "num.dat" file?
    3. In the "num.html" case, perhaps the issue is that the file and graphics are cached by the web browser.

    Another option might be to use a dynamically generated graphic from\ a <acronym>CGI</acronym> script (this is a common example for people learning CGI).