Apache-forks

 view release on metacpan or  search on metacpan

lib/Apache/forks.pm  view on Meta::CPAN

This differs from pure CGI-style execution, where every CGI has its own unique
thread group (isolated from all other Apache process handlers) and each CGI
always begins execution as the main thread.

=head2 threads->list and $thr->join differences in mod_perl

Methods that operate other threads should be treated with care. For example, if you
were successfully doing the following in CGI:

 threads->new({'context' => 'scalar'}, sub {...}) for 1..5;
 push @results, $_->join foreach threads->list(threads::running); #<-- don't do this
 
or

 threads->new({'context' => 'scalar'}, sub {...}) for 1..5;
 $_->join foreach threads->list(threads::joinable);	#<-- don't do this

the join operation may inadvertantly join threads started by from other Apache
handler processes executing threaded code at the same time!

Do the following in mod_perl instead:

 push @my_threads, threads->new({'context' => 'scalar'}, sub {...}) for 1..5;
 push @results, $_->join foreach @my_threads;
 
or

 push @my_threads, threads->new({'context' => 'scalar'}, sub {...}) for 1..5;
 $_->join foreach map($_->is_joinable ? $_ : (), @my_threads);
 
The good news about making such logic changes is that they will work both in CGI
and mod_perl modes.  If you code all your threaded CGIs in this style, your code
should work fine without changes when switching to mod_perl.

=head1 TODO

Determine why mod_perl appears to skip END blocks of child threads (threads
started in an apache-forked handler process) that complete and exit safely.
This isn't necessarily harmful, but should be resolved to insure highest level
of application and memory stability.

=head1 CAVIATS

This module will only work with Apache httpd 1.3.0 or newer.  This is due to the
lack of mod_perl support for PerlChildInitHandler directive.  See L<mod_perl/"mod_perl">
for more information regarding this.

For Apache 2.x, this module currently only supports the MPM (Multi-Processing Module)
L<http://httpd.apache.org/docs/2.0/mod/prefork.html#prefork>.
This is due to the architecture of L<forks>, which only supports one perl thread per
process.

=head1 BUGS

=head1 CREDITS

=over

=item Apache::DBI

Provided the general framework to seamlessly load a module and execute a
subroutine on init of each Apache child handler process for both Apache 1.3.x 
and 2.x.

=back

=head1 AUTHOR

Eric Rybski, <rybskej@yahoo.com>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2007-2008 Eric Rybski <rybskej@yahoo.com>.
All rights reserved.  This program is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

L<forks>, L<forks::shared>.

=cut



( run in 0.581 second using v1.01-cache-2.11-cpan-e1769b4cff6 )