You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by John Drago <jd...@e-commedia.net> on 2004/03/05 17:42:13 UTC

Automatic recurring events (think cron for ASP)

Hi,

Say hypothetically that I want a certain block of code to run every 5
minutes.

Would I...
	a) fork() off a child process in a script loaded up with a
PerlRequire directive in the httpd.conf?

	b) Use $r->register_cleanup(...) to handle the fork()ing and all
that? (kludgy because of forking off a whole new server process)

	c) Simply use a cron job to execute a different script? (But how
would I get the Apache::ASP objects? [$Server/$Session/$Application])

	d) Use a cron job to execute code that sends an http request to
an ASP page on the server? (Even though this works great, it seems wrong
somehow).

It might not be platform-independent, but it would be nice to spawn a
separate thread (not a fork()ed process) to take care of things.

For Win32 we could use Win32::Process <
http://search.cpan.org/~gsar/libwin32-0.191/Process/Process.pm > on
Windows and Threads or forks <
http://search.cpan.org/~elizabeth/forks-0.15/lib/forks.pm > for
non-windows systems.

I imagine something like my $id = $Server->add_recurring_event( sub{ ...
}, 60*60*5 ); for something to run every 5 minutes.
And $Server->end_recurring_event( $id ); to stop the recurring event
from executing.

Something like JavaScript's window.setInterval("alert('This is an
interval!')", 60*60*5) and window.clearInterval( <id> );

I could use something like this to manage cached database connections,
rotate logs, update a "who's online" list, clean out unused sessions,
etc.

If there is already a clean way to do this that I am simply not aware
of, I would like a pointer in the right direction.
And if this is not currently available, I would like to take a stab at
making it available.

Thanks!

_______________________________________________________________

John Drago | Chief Architect of Software Development
E-com Media Group, Inc. [www.e-commedia.com] 
office
::
 303.790.7940 x25
email
::
 jdrago@e-commedia.com



E - b u s i n e s s   w i t h   D i m e n s i o n TM




---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Automatic recurring events (think cron for ASP)

Posted by Josh Chamas <jo...@chamas.com>.
John Drago wrote:
> Hi,
> 
> Say hypothetically that I want a certain block of code to run every 5
> minutes.
> 
> Would I...
> 	a) fork() off a child process in a script loaded up with a
> PerlRequire directive in the httpd.conf?
> 
> 	b) Use $r->register_cleanup(...) to handle the fork()ing and all
> that? (kludgy because of forking off a whole new server process)
> 
> 	c) Simply use a cron job to execute a different script? (But how
> would I get the Apache::ASP objects? [$Server/$Session/$Application])
> 
> 	d) Use a cron job to execute code that sends an http request to
> an ASP page on the server? (Even though this works great, it seems wrong
> somehow).
> 

I would advocate (d), because something as precise as needing something
done every 5 minutes falls in the domain of cron.  Then just running an
lwp-request against a URL is trivial.

Alternatively, if you just want to cache something for 5 minutes, the
the $Response->Include({ Cache => 1, ... }) API and cache an includes
output for 300 seconds.  Includes can return cached data for example.
In this one, one may cache an expensive calculation, just by wrapping
it up in an include.  For the cache API, check out:

   http://www.apache-asp.org/objects.html#%24Response-%3EIa3beea1e

Note, use caching prudently.  Its as slow as the CacheDB access layer,
so should only be used for expensive calculations, say those that take
longer than .005-.01 seconds to run. ( machine dependent of course ).
Using a MLDBM::Sync::SDBM_File layer can be as fast as .002 seconds to fetch
smaller bits of data.  DB_File and GDBM_File can be slower but scale better
to larger data sets.

Regards,

Josh
________________________________________________________________________
Josh Chamas, Founder    | NodeWorks - http://www.nodeworks.com
Chamas Enterprises Inc. | NodeWorks Directory - http://dir.nodeworks.com
http://www.chamas.com   | Apache::ASP - http://www.apache-asp.org



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Automatic recurring events (think cron for ASP)

Posted by Warren Young <wa...@etr-usa.com>.
John Drago wrote:

> 	d) Use a cron job to execute code that sends an http request to
> an ASP page on the server? (Even though this works great, it seems wrong
> somehow).

This is the right way.

All the cron job has to do kick off the event:

	*/5 * * * * wget -O /dev/null http://localhost/dosomething.asp

All the code to actually dosomething is on the ASP side, hence you have 
access to all the ASP variables.

The main problem with this method is that you may need to hide 
dosomething.asp in an .htpasswd protected directory so outsiders can't 
call it.  Use wget's --http-user and --http-passwd flags to call the 
protected script.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org