Loading ...
Sorry, an error occurred while loading the content.

RE: [ANNOUNCE] Apache::ASP Style Guide, first release

Expand Messages
  • David Morton
    ... This begs a big question that was answered somewhat indirectly: Where do you create the database connection? Due to the persistant nature of mod_perl
    Message 1 of 6 , Aug 28, 2002
    • 0 Attachment
      > > I thought mentioning the OnStart handler for db connection was
      > great. Perhaps add a $dbh = undef or whatever in the OnEnd handler
      > to disconnect? (I know you have the cleanup rollback there... but is
      > that different?)
      > >
      > > I'm sure there are some others but I can't think of them right now!
      > >
      >
      > Thanks. Its a good point for memory freeing. I just added
      > it to the example.

      This begs a big question that was answered somewhat indirectly:
      Where do you create the database connection?

      Due to the persistant nature of mod_perl (about which I am just learning),
      It is important to get that right. Is this every time the page hits, or that
      the page is compiled, ie the first time this particular apache process runs
      this script?

      It seems that the best efficiency for a busy site would be to load a connection
      up the first time an apache process loads the script, which should be safe, as
      only one script at a time could use that reference. OTOH, a lightly used site
      would hold a lot of uneeded connections.

      Another stle question: I have an app that use a lot of variables like $bgcolor
      and such so I can change just one spot, and it changes all over the
      application. $Application->{bgcolor} seems like a logical place to put it.

      I assumed then, that Application_OnStart was the place to put definitions like
      these; unfortunately, it didn't seem to work, even when I killed apache
      altogether and restarted.
      What should I do?


      --
      David Morton (620) 342-9297
      Vice President mortonda@...
      Osprey Network Technologies, Inc.
      1015 Scott
      Emporia, KS 66801



      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • ellers@iinet.net.au
      ... I just always do it in Script_OnStart. The site I used this with is fine like this ... although having said that it doesn t make huge demands on the DB.
      Message 2 of 6 , Aug 28, 2002
      • 0 Attachment
        > > > I thought mentioning the OnStart handler for db connection was
        > > great. Perhaps add a $dbh = undef or whatever in the OnEnd handler
        > > to disconnect? (I know you have the cleanup rollback there... but is
        > > that different?)
        > > >
        > > Thanks. Its a good point for memory freeing. I just added
        > > it to the example.
        >
        > This begs a big question that was answered somewhat indirectly:
        > Where do you create the database connection?

        I just always do it in Script_OnStart. The site I used this with is fine like this ... although having said that it doesn't make huge demands on the DB.


        > Due to the persistant nature of mod_perl (about which I am just learning),
        > It is important to get that right. Is this every time the page hits, or that
        > the page is compiled, ie the first time this particular apache process runs
        > this script?

        If in the Script_OnStart it is every time the page is returned back to the requester. Similarly with the Script_OnEnd for cleaning up the connection. With MySQL (can't speak for other DBs) the connection seems to be quite light-weight...


        > Another stle question: I have an app that use a lot of variables like $bgcolor
        > and such so I can change just one spot, and it changes all over the
        > application. $Application->{bgcolor} seems like a logical place to put it.
        >
        > I assumed then, that Application_OnStart was the place to put definitions like
        > these; unfortunately, it didn't seem to work, even when I killed apache
        > altogether and restarted.
        > What should I do?

        Josh or another list member probably has the "right" answer... but my simple solution to constants is to them in either the Script_OnStart section (prob not necessary in the case of constants) or just in the global.asa file, anywhere.

        HTH
        Ellers

        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Josh Chamas
        ... Yes, use Script_OnStart for best effect. If you want to cache your database connections from request to request, which you need to do for heavy
        Message 3 of 6 , Aug 29, 2002
        • 0 Attachment
          >>This begs a big question that was answered somewhat indirectly:
          >>Where do you create the database connection?
          >
          >
          > I just always do it in Script_OnStart. The site I used this with is fine like this ... although having said that it doesn't make huge demands on the DB.
          >

          Yes, use Script_OnStart for best effect. If you want to cache your database
          connections from request to request, which you need to do for heavy
          connections like to Oracle, make sure to just "use Apache::DBI" before
          you ever "use DBI". The best place for this is in a mod_perl style
          startup.pl script that you PerlRequire early on. What Apache::DBI does
          is make it so that a normal DBI->connect just returns a cached connection
          next time it is asked for, so the connection caching is done for you
          transparently.

          >
          >
          >>Due to the persistant nature of mod_perl (about which I am just learning),
          >>It is important to get that right. Is this every time the page hits, or that
          >>the page is compiled, ie the first time this particular apache process runs
          >>this script?
          >

          Script_OnStart is run before each time a script is executed regardless of
          page compilation.

          >
          >>Another stle question: I have an app that use a lot of variables like $bgcolor
          >>and such so I can change just one spot, and it changes all over the
          >>application. $Application->{bgcolor} seems like a logical place to put it.
          >>

          I would recommend you stay away from using $Application for much at all,
          and especially things like this. The current definition of Application_OnStart
          is such that it may only get run once during the lifetime of you application,
          as long as your application is in continual use.

          Much better to configure a global hash like this:

          #global.asa

          use vars qw(%Config);
          %Config = (
          bgcolor => 'white',
          text => 'black',
          );

          and then reference your $Config{bgcolor} in your scripts.
          If you would prefer to hijack $Application for this, you could set

          PerlSetVar AllowApplicationState 0

          so that $Application would not be defined, then set your own
          $Application like above in global.asa:

          $Application = {
          bgcolor => 'white',
          text => 'black',
          };

          The default $Application is a file dbm based cache, and though
          not too slow, could hurt performance. The latter $Application
          which you could set up yourself is a per process in memory object
          that would be perfect for read-only access.

          Regards,

          Josh
          ________________________________________________________________
          Josh Chamas, Founder phone:925-552-0128
          Chamas Enterprises Inc. http://www.chamas.com
          NodeWorks Link Checking http://www.nodeworks.com


          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        Your message has been successfully submitted and would be delivered to recipients shortly.