Question
Whenever I run statistics either manualy or from cron, my error log gets:
[Sun Jul 21 20:01:34 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 52.
[Sun Jul 21 20:01:34 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 53.
[Sun Jul 21 20:01:34 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 71.
[Sun Jul 21 20:01:34 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 135.
[Sun Jul 21 20:01:34 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 152.
[Sun Jul 21 20:01:34 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 296.
This is since I have added the settings from
ModPerl (.htaccess settings and PerlTaintCheck).
- TWiki version: 01 Dec 2001
- Web server: Apache/1.3.26 (Unix) mod_perl/1.27 mod_ssl/2.8.10 OpenSSL/0.9.6a
- Server OS: FreeBSD 4.6
- Web browser: IE 6
- Client OS: XP/Home
--
DrewCard - 22 Jul 2002
Answer
Interesting - sounds like this is not serious as these 2 variables are only assigned to once. In any case, you should not run the
statistics script under mod_perl, since the Dec2001 version uses a lot of memory.
Please download the latest version of this script, from
CVSget:bin/statistics
, and see whether this has the same problem (I think it will) - this version also uses much less memory since it was rewritten. Patches will be very welcome as I don't have mod_perl
--
RichardDonkin - 22 Jul 2002
I forgot to mention that the statisticts results don't appear to be impacted, I assume the message above is some type of warning rather than an actual error. Updateing to this mornings CVS version appears to only change the line numbers:
[Mon Jul 22 07:44:45 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 61.
[Mon Jul 22 07:44:45 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 62.
[Mon Jul 22 07:44:45 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 80.
[Mon Jul 22 07:44:45 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 190.
[Mon Jul 22 07:44:45 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 341.
[Mon Jul 22 07:44:45 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 482.
And turning off mod_perl stops the warning from appearing.
I took one thing from
http://perl.com/pub/a/2002/05/07/mod_perl.html
and added 'use diagnostics;' to statistics and re ran.
This resulted in the below message:
Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics
line 62 (#1)
(W) An inner (nested) named subroutine is referencing a lexical
variable defined in an outer subroutine.
When the inner subroutine is called, it will probably see the value of
the outer subroutine's variable as it was before and during the
*first* call to the outer subroutine; in this case, after the first
call to the outer subroutine is complete, the inner and outer
subroutines will no longer share a common value for the variable. In
other words, the variable will no longer be shared.
Furthermore, if the outer subroutine is anonymous and references a
lexical variable outside itself, then the outer and inner subroutines
will never share the given variable.
This problem can usually be solved by making the inner subroutine
anonymous, using the sub {} syntax. When inner anonymous subs that
reference variables in outer subroutines are called or referenced,
they are automatically rebound to the current values of such
variables.
I hope the above is informational, as all it does for me is hurt my brain (hmmm... coffee....).
Okay, one more thing,
Looking at lines 39-41 of statistics I see:
#open(STDERR,'>&STDOUT'); # redirect error to browser
# FIXME: Beware global $| in mod_perl! Should use 'local'
$| = 1; # no buffering
Does that sugest my fix?
--
DrewCard - 22 Jul 2002
These
two red lines at the top of main should fix the problem:
my $logDate = "";
$isCgi = "";
$cgiQuery = "";
# determine at runtime if script is called by browser or cron job
if( $ENV{'DOCUMENT_ROOT'} ) {
Could you confirm?
--
PeterThoeny - 23 Jul 2002
Adding the two lines as above to either of the statistics programs (Dec 01 and CVS Jul22) does change the error messages (Dec 01 below):
[Tue Jul 23 07:54:55 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 48.
[Tue Jul 23 07:54:55 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 49.
[Tue Jul 23 07:54:55 2002] statistics: Subroutine main redefined at /usr/local/www/twiki/bin/statistics line 42.
[Tue Jul 23 07:54:55 2002] statistics: Variable "$cgiQuery" will not stay shared at /usr/local/www/twiki/bin/statistics line 154.
[Tue Jul 23 07:54:55 2002] statistics: Subroutine processWeb redefined at /usr/local/www/twiki/bin/statistics line 150.
[Tue Jul 23 07:54:55 2002] statistics: Subroutine getTopList redefined at /usr/local/www/twiki/bin/statistics line 242.
[Tue Jul 23 07:54:55 2002] statistics: Variable "$isCgi" will not stay shared at /usr/local/www/twiki/bin/statistics line 298.
[Tue Jul 23 07:54:55 2002] statistics: Subroutine printMsg redefined at /usr/local/www/twiki/bin/statistics line 284.
--
DrewCard - 23 Jul 2002
By the way, the other reason not to run
statistics under mod_perl, even if this issue is fixed, is something to do with
$| - I think this gets shared across all mod_perl instances or something, which is not necessarily good... Much easier to just create another directory outside the current
bin directory, and enable this for CGI and not mod_perl - long statistics jobs are exactly the sort of thing that should not be run within a mod_perl Apache process, IMO, as there is no performance benefit and they will use one of the available mod_perl processes, possibly causing a new one to be created (which is fairly expensive). However, I am not a mod_perl performance guru...
--
RichardDonkin - 23 Jul 2002
Richard brings up a good point, better to run the script not under mod_perl.
Nevertheless I made some more fixes, get the latest script from
CVSget:bin/statistics
. Could you confirm?
--
PeterThoeny - 23 Jul 2002
Since I am enableing mod_perl in the .htaccess shouldn't I be able to tweak the settings there-in to not use the mod_perl for bin/statistics ? Or would it be better to make the seperate directory, or even adjust it so that it's not possible to update statistics from the web interface...
Peter, after implementing todays statistics program I now get no messages to the error log when running statistics. (whoot!!)
However I have gotten this message three times, I
think it hast to do with mod_perl noticing the change to 'statistics' but I am not sure.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine main redefined at /usr/local/www/twiki/bin/statistics line 47.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine debugPrintHash redefined at /usr/local/www/twiki/bin/statistics line 202.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine collectLogData redefined at /usr/local/www/twiki/bin/statistics line 234.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine processWeb redefined at /usr/local/www/twiki/bin/statistics line 336.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine getTopList redefined at /usr/local/www/twiki/bin/statistics line 436.
[Tue Jul 23 18:00:01 2002] statistics: Subroutine printMsg redefined at /usr/local/www/twiki/bin/statistics line 478.
Looks good...
running away before the power goes out
--
DrewCard - 23 Jul 2002
I am not familiar with mod_perl, can't give you and answer with the messages you get. Very possible as you say.
The statistics script is usually called by a cron job. You could remove the update statistics link, or just leave it the way it is. The chance that two person manually update the stats at the same time is very slim
--
PeterThoeny - 24 Jul 2002