You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Arnaud Blancher <Ar...@ungi.net> on 2004/09/17 15:36:22 UTC

problem of persistance

hi all

with mp2 1.99_14,perl 5.8.5,apache 2.0.50
i have a problem of persistance.

I just print IP, time and pid.
when 2  computer get the script they sometimes see the have the same IP 
and the same time !

i would like all my variable aren't share
and especially the $user object

so could you tell me if i'm wrong or if it's a bug ?

thank's
Arnaud
#----------------------------------------------------------------------------------------------------------
#  test.pl
#----------------------------------------------------------------------------------------------------------
#!/usr/bin/perl

package Test;
use strict;
use CGI qw(:standard);
use lib('/home/GESINT/cgi-bin');


use My_module;
my $user = My_module->new(ip=>$ENV{'REMOTE_ADDR'},pid=>$$);

&taff2();

sub taff2 {

 print header();
 print 'IP: ' . $user->ip . "<br>\n";
 print 'PID: ' . $user->pid  . "<br>\n";
 print 'TIME: ' . $user->dat  . "<br>\n";

  return 1;
}

1;

#----------------------------------------------------------------------------------------------------------
#  My_module.pm
#----------------------------------------------------------------------------------------------------------
package My_module;
use strict;

sub new {
  my $invoquant = shift;
  my $classe = ref($invoquant) || $invoquant;
  my $self = { @_ };
  bless ($self,$classe);

  $self->dat(time);
 
  return $self;
}

sub ip {
  my $self = shift;
  $self->{ip} = shift if @_;
  return $self->{ip};
};

sub pid {
  my $self = shift;
  $self->{pid} = shift if @_;
  return $self->{pid};
};

sub dat {
  my $self = shift;
  $self->{dat} = shift if @_;
  return $self->{dat};
};

sub DESTROY {
  my $self = shift;
};

#----------------------------------------------------------------------------------------------------------

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2004-09-20 at 06:41, Arnaud Blancher wrote:
> i see the potential problem of mod perl but it's not a really good solution
> to change the script every times i want to test !

Perl is not going to warn you about this because it is actually legal to
do it this way in perl.  There's no way for Perl to know that you didn't
intend for the variables you put in the closure to keep their values
between requests.

The best thing to do is to always pass all variables (except constants)
to all of your subs, or switch to an object-oriented coding approach. 
The kind of coding where you just use variables that are in scope from a
subroutine without passing them explicitly to the sub is a bad practice
because it means your subroutines are "tightly coupled" to the
surrounding code and it makes it difficult to move them into modules or
to debug them.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Tom Schindl <to...@gmx.at>.
Arnaud Blancher wrote:
[...]

> third
> i put  a 'use warning' in the script.
> In the apache error log i see the warning. that's ok
> but i must restart the serveur when i change a module, that's more boring .
> 
> is it better way to test ?
> 
Are you looking for http://perl.apache.org/docs/2.0/api/Apache/Reload.html?

> At this time, there noting in the
> http://perl.apache.org/docs/2.0/devel/debug/perl.html
> :-(
> 
> maybe i'm the once to bug !
> 
> 
> Arnaud.
> 
> 
> 


Reclaim Your Inbox!
http://www.mozilla.org/products/thunderbird

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Arnaud Blancher <Ar...@ungi.net>.
Stas Bekman wrote:

> Arnaud Blancher wrote:
>
>> thank you
>> it's seems to be ok.
>> i ll read again closure in camel book !
>
>
> See also:
> http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Understanding_Closures____the_Easy_Way 
>
>
>
>
ok

first, i suppose i can't forbiden closure in my script !
but it was a good option for me !

second
the little probleme is when i test script with
perl -wc ./test.pl
i have no warning ... so that no easy to see
it will a problem under MP

when i put all my script in a
sub run {
...
}
i see the potential problem of mod perl but it's not a really good solution
to change the script every times i want to test !
but i  see the warning :-)

third
i put  a 'use warning' in the script.
In the apache error log i see the warning. that's ok
but i must restart the serveur when i change a module, that's more boring .

is it better way to test ?

At this time, there noting in the
http://perl.apache.org/docs/2.0/devel/debug/perl.html
:-(

maybe i'm the once to bug !


Arnaud.



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Stas Bekman <st...@stason.org>.
Arnaud Blancher wrote:
> thank you
> it's seems to be ok.
> i ll read again closure in camel book !

See also:
http://perl.apache.org/docs/general/perl_reference/perl_reference.html#Understanding_Closures____the_Easy_Way



-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Arnaud Blancher <Ar...@ungi.net>.
thank you
it's seems to be ok.
i ll read again closure in camel book !

Arnaud

>
> You are creating a closure.  Easy to fix:
>
>> use My_module;
>> my $user = My_module->new(ip=>$ENV{'REMOTE_ADDR'},pid=>$$);
>>
>> &taff2();
>
>
> Make that:
>
> taff2($user);
>
>> sub taff2 {
>
>
> add this to the beginning of taff2:
>
> my $user = shift;
>
> - Perrin
>


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Perrin Harkins <pe...@elem.com>.
Arnaud Blancher wrote:
> i would like all my variable aren't share
> and especially the $user object

You are creating a closure.  Easy to fix:

> use My_module;
> my $user = My_module->new(ip=>$ENV{'REMOTE_ADDR'},pid=>$$);
> 
> &taff2();

Make that:

taff2($user);

> sub taff2 {

add this to the beginning of taff2:

my $user = shift;

- Perrin

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: problem of persistance

Posted by Arnaud Blancher <Ar...@ungi.net>.
the complete config:


-------------8<---------- Start Bug Report ------------8<----------
1. Problem Description:

  [DESCRIBE THE PROBLEM HERE]

2. Used Components and their Configuration:

*** mod_perl version 1.9914

*** using lib/Apache/BuildConfig.pm
*** Makefile.PL options:
  MP_AP_PREFIX    => /usr/local/httpd/prefork
  MP_COMPAT_1X    => 1
  MP_DEBUG        => 1
  MP_GENERATE_XS  => 1
  MP_INST_APACHE2 => 1
  MP_LIBNAME      => mod_perl
  MP_TRACE        => 1
  MP_USE_DSO      => 1
  MP_USE_STATIC   => 1


*** /usr/local/httpd/prefork/bin/httpd -V
Server version: Apache/2.0.50
Server built:   Sep  7 2004 14:07:10
Server's Module Magic Number: 20020903:8
Architecture:   32-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D HTTPD_ROOT="/usr/local/httpd/prefork"
 -D SUEXEC_BIN="/usr/local/httpd/prefork/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"


*** /usr/local/perl5.8.5/bin/perl5.8.5 -V
Summary of my perl5 (revision 5 version 8 subversion 5) configuration:
  Platform:
    osname=linux, osvers=2.4.18-bf2.4, archname=i686-linux
    uname='linux gesint 2.4.18-bf2.4 #1 son apr 14 09:53:28 cest 2002 
i686 unknown '
    config_args='-Dprefix=/usr/local/perl5.8.5 -Doptimize=-g -Dusedevel'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe 
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-g',
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='2.95.4 20011002 (Debian prerelease)', 
gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/include
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING USE_LARGE_FILES
  Built under linux
  Compiled at Sep  7 2004 12:06:24
  %ENV:
    PERL_LWP_USE_HTTP_10="1"
  @INC:
    /usr/local/perl5.8.5/lib/5.8.5/i686-linux
    /usr/local/perl5.8.5/lib/5.8.5
    /usr/local/perl5.8.5/lib/site_perl/5.8.5/i686-linux
    /usr/local/perl5.8.5/lib/site_perl/5.8.5
    /usr/local/perl5.8.5/lib/site_perl
    .

*** Packages of interest status:

Apache::Request: -
CGI            : 3.04
LWP            : 5.800
mod_perl       : 1.9914


3. This is the core dump trace: (if you get a core dump):

  [CORE TRACE COMES HERE]

This report was generated by ./t/REPORT on Fri Sep 17 14:02:33 2004 GMT.

-------------8<---------- End Bug Report --------------8<----------

Note: Complete the rest of the details and post this bug report to
dev <at> perl.apache.org. To subscribe to the list send an empty
email to dev-subscribe@perl.apache.org.




-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html