Apache-ASP

 view release on metacpan or  search on metacpan

site/events.html  view on Meta::CPAN

<font face="courier new" size=3><pre>
  sub Session_OnStart {
      $Application-&gt;{$Session-&gt;SessionID()} = started;
  }
</pre></font>Sessions are easy to understand.  When visiting a page in a
web application, each user has one unique $Session.  This 
session expires, after which the user will have a new
$Session upon revisiting.
<font face="courier new" size=3><pre>
</pre></font>A web application starts when the user visits a page in that
application, and has a new $Session created.  Right before
the first $Session is created, the $Application is created.
When the last user $Session expires, that $Application 
expires also.  For some web applications that are always busy,
the Application_OnEnd event may never occur.</font>
	
	<p>
	<a name=Script_OnSta6a4cfa7f></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnStart & Script_OnEnd</b></font>
<font face="courier new" size=3><pre>
</pre></font>The script events are used to run any code for all scripts
in an application defined by a global.asa.  Often, you would
like to run the same code for every script, which you would
otherwise have to add by hand, or add with a file include,
but with these events, just add your code to the global.asa,
and it will be run.  
<font face="courier new" size=3><pre>
</pre></font>There is one caveat.  Code in Script_OnEnd is not guaranteed 
to be run when $Response-&gt;End() is called, since the program
execution ends immediately at this event.  To always run critical
code, use the API extension:
<font face="courier new" size=3><pre>
	$Server-&gt;RegisterCleanup()
</pre></font>
	
	<p>
	<a name=Session_OnSt3cfacd72></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Session_OnStart</b></font>
<font face="courier new" size=3><pre>
</pre></font>Triggered by the beginning of a user&#39;s session, Session_OnStart
gets run before the user&#39;s executing script, and if the same
session recently timed out, after the session&#39;s triggered Session_OnEnd.
<font face="courier new" size=3><pre>
</pre></font>The Session_OnStart is particularly useful for caching database data,
and avoids having the caching handled by clumsy code inserted into
each script being executed.</font>
	
	<p>
	<a name=Session_OnEne9575396></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Session_OnEnd</b></font>
<font face="courier new" size=3><pre>
</pre></font>Triggered by a user session ending, Session_OnEnd can be useful
for cleaning up and analyzing user data accumulated during a session.
<font face="courier new" size=3><pre>
</pre></font>Sessions end when the session timeout expires, and the StateManager
performs session cleanup.  The timing of the Session_OnEnd does not
occur immediately after the session times out, but when the first 
script runs after the session expires, and the StateManager allows
for that session to be cleaned up.  
<font face="courier new" size=3><pre>
</pre></font>So on a busy site with default SessionTimeout (20 minutes) and 
StateManager (10 times) settings, the Session_OnEnd for a particular 
session should be run near 22 minutes past the last activity that Session saw.
A site infrequently visited will only have the Session_OnEnd run
when a subsequent visit occurs, and theoretically the last session
of an application ever run will never have its Session_OnEnd run.
<font face="courier new" size=3><pre>
</pre></font>Thus I would not put anything mission-critical in the Session_OnEnd,
just stuff that would be nice to run whenever it gets run.</font>
	
	<p>
	<a name=Script_OnFludc73a8d8></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnFlush</b></font>
<font face="courier new" size=3><pre>
</pre></font>API extension. This event will be called prior to flushing
the $Response buffer to the web client.  At this time,
the $Response-&gt;{BinaryRef} buffer reference may be used to modify 
the buffered output at runtime to apply global changes to scripts 
output without having to modify all the scripts.
<font face="courier new" size=3><pre>
 sub Script_OnFlush {
   my $ref = $Response-&gt;{BinaryRef};
   $$ref =~ s/\s+/ /sg; # to strip extra white space
 }
</pre></font>Check out the <a href=eg/global.asa>./site/eg/global.asa</a> for an example of its use.</font>
	
	<p>
	<a name=Script_OnPar383e5cdf></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Script_OnParse</b></font>
<font face="courier new" size=3><pre>
</pre></font>This event allows one to set up a source filter on the script text,
allowing one to change the script on the fly before the compilation
stage occurs.  The script text is available in the $Server-&gt;{ScriptRef}
scalar reference, and can be accessed like so:
<font face="courier new" size=3><pre>
 sub Script_OnParse {
   my $code = $Server-&gt;{ScriptRef}
   $$code .= &quot; ADDED SOMETHING &quot;;
 }
</pre></font>
	
	<p>
	<a name=Application_61345d1d></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Application_OnStart</b></font>
<font face="courier new" size=3><pre>
</pre></font>This event marks the beginning of an ASP application, and 
is run just before the Session_OnStart of the first Session
of an application.  This event is useful to load up
$Application with data that will be used in all user sessions.</font>
	
	<p>
	<a name=Application_4bca009c></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Application_OnEnd</b></font>
<font face="courier new" size=3><pre>
</pre></font>The end of the application is marked by this event, which
is run after the last user session has timed out for a 
given ASP application.</font>
	
	<p>
	<a name=Server_OnSta0d174f59></a>
	<font face=verdana><font class=title size=+0 color=#555555><b>Server_OnStart ( pseudo-event )</b></font>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.424 second using v1.00-cache-2.02-grep-82fe00e-cpan-2c419f77a38b )