Apache::fork man page on OpenServer

Man page or keyword search:  
man Server   5388 pages
apropos Keyword Search (all sections)
Output format
OpenServer logo
[printable version]

Apache::fork(3)	      User Contributed Perl Documentation      Apache::fork(3)

NAME
       Apache::fork - Override Perl's built-in fork()

SYNOPSIS
	use Apache::fork;

DESCRIPTION
       The fork function defined in this module will override Perl's built-in
       fork function so that any children resulting from a fork() will
       (optionally) close any open listening http sockets (main server and
       virtuals) and/or kill the child httpd process with exit() is called.

       TOGGLING: forkoption(int) usage:

       int can be one of the following...

       0 = Nothing, perform your normal fork().	 1 = Have the child resulting
       from a fork close all listening sockets.	 2 = Have the child resulting
       from a fork() die with exit() is called.	 3 = Do both 1 and 2.

       Default is 3.

       NOTE: forkoption is NOT reset to default between hits, why?  So you
       could set it in a perlscript and have it last across clients/runs (ie
       so you wouldn't need to go modifying your mod_perl (or in my case, pure
       CGI/perl scripts. ;)

       ALSO NOTE: The parent process will still have the http sockets open, so
       it can still communicate with the downstream client, as well as still
       accept connections after the client has disconnected, it's only the
       resulting child who will no longer have the http sockets open.

       ANOTHER NOTE: The child STILL has the socket open to the client, it's
       just the listening sockets (port 80, etc) that's closed.

       AYA NOTE: ALL listening sockets are closed, for the main server AND for
       any alternative ports you have the httpd process listening to.

       WHY?: Sometimes, you want to have your script fork, then exec a process
       so that it can perform some nifty thing in the background.  Unfortu-
       natly, when you fork (and exec), all open file descriptors are passed
       along, including the listening HTTP sockets that are used by the server
       to accept connections, which can be a bad thing.	 (ie.  Child is
       forked, forked child has port 80 open, forked child exec()'s whatever,
       now whatever has port 80 open, server is HUP'd, restarted, whatever...
       'course, it can't because some other process already has control over
       port 80 (ie, whatever)) Ow?  ;)

       Also, forked children would "hang around" when they were finished (or
       exit()'d) unless exit(-2) was used.  And, the original parent httpd had
       no clue the children even existed.  Essentually, you'd end up with an
       indefinite number of httpd processes (as each forked()'d child would
       never exit).  Of course, with the socket closing patch in place...
       those children never again served another page either.

       This patch was made essentually to make fork() under mod_perl act like
       you'd expect it to (so modules that might be used by non-mod_perl
       scripts wouldn't need to be modified)

       Incase any of you were curious, all my CGI scripts run unmodified under
       mod_perl.  Not a single line of mod_perl anything in them.  If they
       won't work under mod_perl for some odd reason, I just modify mod_perl
       so they do.  ;)

AUTHOR
       Michael Turner, mturner@spry.com

perl v5.8.8			  2007-03-30		       Apache::fork(3)
[top]
                             _         _         _ 
                            | |       | |       | |     
                            | |       | |       | |     
                         __ | | __ __ | | __ __ | | __  
                         \ \| |/ / \ \| |/ / \ \| |/ /  
                          \ \ / /   \ \ / /   \ \ / /   
                           \   /     \   /     \   /    
                            \_/       \_/       \_/ 
More information is available in HTML format for server OpenServer

List of man pages available for OpenServer

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net