1Net::Server::PreForkSimUpsleer(3C)ontributed Perl DocumeNnetta:t:iSoenrver::PreForkSimple(3)
2
3
4
6 Net::Server::PreForkSimple - Net::Server personality
7
9 use Net::Server::PreForkSimple;
10 @ISA = qw(Net::Server::PreForkSimple);
11
12 sub process_request {
13 #...code...
14 }
15
16 __PACKAGE__->run();
17
19 Please read the pod on Net::Server first. This module is a
20 personality, or extension, or sub class, of the Net::Server module.
21
22 This personality binds to one or more ports and then forks
23 "max_servers" child processes. The server will make sure that at any
24 given time there are always "max_servers" available to receive a client
25 request. Each of these children will process up to "max_requests"
26 client connections. This type is good for a heavily hit site that can
27 keep "max_servers" processes dedicated to the serving. (Multi port
28 accept defaults to using flock to serialize the children).
29
30 At this time, it does not appear that this module will pass tests on
31 Win32 systems. Any ideas or patches for making the tests pass would be
32 welcome.
33
35 Please see the sample listed in Net::Server.
36
38 In addition to the command line arguments of the Net::Server base
39 class, Net::Server::PreFork contains several other configurable
40 parameters.
41
42 Key Value Default
43 max_servers \d+ 50
44 max_requests \d+ 1000
45
46 serialize (flock|semaphore|pipe) undef
47 # serialize defaults to flock on multi_port or on Solaris
48 lock_file "filename" POSIX::tmpnam
49
50 check_for_dead \d+ 30
51
52 max_dequeue \d+ undef
53 check_for_dequeue \d+ undef
54
55 max_servers
56 The maximum number of child servers to start and maintain. This
57 does not apply to dequeue processes.
58
59 max_requests
60 The number of client connections to receive before a child
61 terminates.
62
63 serialize
64 Determines whether the server serializes child connections.
65 Options are undef, flock, semaphore, or pipe. Default is undef.
66 On multi_port servers or on servers running on Solaris, the default
67 is flock. The flock option uses blocking exclusive flock on the
68 file specified in lock_file (see below). The semaphore option uses
69 IPC::Semaphore (thanks to Bennett Todd) for giving some sample
70 code. The pipe option reads on a pipe to choose the next. the
71 flock option should be the most bulletproof while the pipe option
72 should be the most portable. (Flock is able to reliquish the block
73 if the process dies between accept on the socket and reading of the
74 client connection - semaphore and pipe do not)
75
76 lock_file
77 Filename to use in flock serialized accept in order to serialize
78 the accept sequece between the children. This will default to a
79 generated temporary filename. If default value is used the
80 lock_file will be removed when the server closes.
81
82 check_for_dead
83 Seconds to wait before checking to see if a child died without
84 letting the parent know.
85
86 max_dequeue
87 The maximum number of dequeue processes to start. If a value of
88 zero or undef is given, no dequeue processes will be started. The
89 number of running dequeue processes will be checked by the
90 check_for_dead variable.
91
92 check_for_dequeue
93 Seconds to wait before forking off a dequeue process. The
94 run_dequeue hook must be defined when using this setting. It is
95 intended to use the dequeue process to take care of items such as
96 mail queues. If a value of undef is given, no dequeue processes
97 will be started.
98
100 "Net::Server::PreFork" allows for the use of a configuration file to
101 read in server parameters. The format of this conf file is simple key
102 value pairs. Comments and white space are ignored.
103
104 #-------------- file test.conf --------------
105
106 ### server information
107 max_servers 80
108
109 max_requests 1000
110
111 ### user and group to become
112 user somebody
113 group everybody
114
115 ### logging ?
116 log_file /var/log/server.log
117 log_level 3
118 pid_file /tmp/server.pid
119
120 ### access control
121 allow .+\.(net|com)
122 allow domain\.com
123 deny a.+
124
125 ### background the process?
126 background 1
127
128 ### ports to bind
129 host 127.0.0.1
130 port localhost:20204
131 port 20205
132
133 ### reverse lookups ?
134 # reverse_lookups on
135
136 #-------------- file test.conf --------------
137
139 Process flow follows Net::Server until the loop phase. At this point
140 "max_servers" are forked and wait for connections. When a child
141 accepts a connection, finishs processing a client, or exits, it relays
142 that information to the parent, which keeps track and makes sure there
143 are always "max_servers" running.
144
146 The PreForkSimple server has the following hooks in addition to the
147 hooks provided by the Net::Server base class. See Net::Server
148
149 "$self->run_n_children_hook()"
150 This hook occurs at the top of run_n_children which is called each
151 time the server goes to start more child processes. This gives the
152 parent to do a little of its own accountting (as desired). Idea
153 for this hook came from James FitzGibbon.
154
155 "$self->child_init_hook()"
156 This hook takes place immeditately after the child process forks
157 from the parent and before the child begins accepting connections.
158 It is intended for any addiotional chrooting or other security
159 measures. It is suggested that all perl modules be used by this
160 point, so that the most shared memory possible is used.
161
162 "$self->child_finish_hook()"
163 This hook takes place immediately before the child tells the parent
164 that it is exiting. It is intended for saving out logged
165 information or other general cleanup.
166
167 "$self->run_dequeue()"
168 This hook only gets called in conjuction with the check_for_dequeue
169 setting.
170
172 Tests don't seem to work on Win32. Any ideas or patches would be
173 welcome.
174
176 See Net::Server
177
179 Paul T. Seamons paul@seamons.com
180
182 See Net::Server
183
185 Please see also Net::Server::Fork, Net::Server::INET,
186 Net::Server::PreFork, Net::Server::MultiType, Net::Server::Single
187 Net::Server::SIG Net::Server::Daemonize Net::Server::Proto
188
189
190
191perl v5.12.0 2007-03-26 Net::Server::PreForkSimple(3)