You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tomas Zeman <to...@yahoo.com> on 2000/06/30 20:42:13 UTC
Global variables II [and DBI]
OK thanks,
but how I create a global variable, which will be
global for all apache processes together ?
and I have nother problem what is a right usage of
using DBI in script ?
I have a Apache::DBI , DBI and connect_on_init in my
startup.pl and connection is established OK.
what should than i use in my script
------
use DBI;
or
Apache::DBI; ?
, with
$dbd = DBI->connect(...)
or
$dbd ||= DBI->connect(....)
or Apache::DBI->connect ??
-------
to make it effective and use precreated connection
from startup.pl ?
Thanks a lot
Tomas Zeman
> seems to me, that the script is working as it
should.. >you are just
> hitting several different instances of the script..
>one for each
> apache child process.. try starting apache with the
>-X flag.
> './httpd -X' .. this will cause apache to run in
>single process mode..
>
> hope this helps.
>
.On Thu, 29 Jun 2000, Tomas Zeman wrote:.
>
> Hi all,
>
> I am new to mod_perl and i have one problem<br>
>
> I want to rewrite this simple script from fastcgi to
> mdo_perl
> ---------
> use FCGI;
> $cnt = 0;
> while (FCGI::Accept)
> {
> print "Content-type:text/html\n\n";
> print $cnt++;
> }
> ---------
>
> This script writes (when i relaod it) 1,2,3,4,5,...
> and $cnt is "global variable"
>
> in mod_perl
> I created My.pm package
> -----------
> package My;
>
> use strict;
> use Apache::Constants qw(:common);
>
> # I try both global variable possibilites
> use vars qw($cnt1);
> $My::cnt2 = 1;
>
> my $cnt1 = 1;
>
> sub increment{
> $My::cnt2++;
> $cnt++;
> print "$cnt1<br>";
> print $My::cnt2;
> }
> 1;
> -----------
>
> I have this module in starup.pl and start it when
> apache start
>
> I also have a script when i use My.pm module
> -----------
> #!/usr/bin/perl -w
>
> use strict;
> use Apache::Registry;
> use My;
>
> print "Content-type:text/html\n\n";
>
>
> $rr = Myy->increment();
> print "<br>$rr<br>";
> -----------
>
> This script writes 1,1,1,2,2,2,3,3,3,2,2,3,4,2,1
.....
> randomly !!
>
> Can anybody help me, where is the problem ?
>
>
> Thanks a lot
> Tomas Zeman
>
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/
Re: Global variables II [and DBI]
Posted by Perrin Harkins <pe...@primenet.com>.
On Fri, 30 Jun 2000, Tomas Zeman wrote:
> but how I create a global variable, which will be
> global for all apache processes together ?
You have to use either shared memory (IPC::ShareLite, IPC::Shareable,
IPC::MM) or an external storage method like flat files, dbm files, or a
relational database. You may want to look at Apache::Session which is
intended to solve this problem.
> I have a Apache::DBI , DBI and connect_on_init in my
> startup.pl and connection is established OK.
> what should than i use in my script