[Catalyst] post page serving or forking

Brandon Black blblack at gmail.com
Tue Feb 21 04:22:52 CET 2006


On 2/20/06, apv <ashley at sedition.com> wrote:
> Is there an approved or built-in way to fork something out or
> handle it post page serve.
>
> I want to do some referring catching and *sometimes* do a ping
> back to prove that the referrer wasn't referrer spam. The ping
> back can obviously take up to several seconds.
>
> I'm a little scared to just fork() b/c I don't understand the internals
> of
> FastCGI or modperl + Catalyst well enough to know if that's safe.
>

I definitely dount it would be safe/sane to just fork() under all of
the engines, although some will handle it better than others.

If it were me, and I wanted some asynchronous offline (with respect to
requests) checking of something, I would probably do it through a
database table to a seperate daemon.

Like in your example (if I understand it correctly), I might create a
table check_referrers with a  pk column "referrer", and in the
controller code do something like:

if(rand(100)<10) { # check 10% of requests
    $c->model('MyDB::CheckReferrers')->find_or_create({ referrer => $foo });
}

And then completely seperately, run a perl daemon which also uses your
database schema class, and periodically scans the entries in this
table and does the checking, and takes whatever action (send you an
email report, or log the summarized results to yet another table
that's viewable via an admin-only catalyst interface).

You could even add a column "checked BOOLEAN" and a timestamp column
that defaults to current_timestamp on insert.  Then have the daemon
flag them checked when they've been checked once already, and
periodically delete entries that were inserted more than X time ago to
make sure they get re-checked from time to time if they crop up much
later.  It would be pretty efficient.

-- Brandon



More information about the Catalyst mailing list