Net::Server::PreForkSimple − Net::Server personality


  use Net::Server::PreForkSimple;
  @ISA = qw(Net::Server::PreForkSimple);
  sub process_request {


Please read the pod on Net::Server first. This module is a personality, or extension, or sub class, of the Net::Server module.

This personality binds to one or more ports and then forks "max_servers" child processes. The server will make sure that at any given time there are always "max_servers" available to receive a client request. Each of these children will process up to "max_requests" client connections. This type is good for a heavily hit site that can keep "max_servers" processes dedicated to the serving. (Multi port accept defaults to using flock to serialize the children).

At this time, it does not appear that this module will pass tests on Win32 systems. Any ideas or patches for making the tests pass would be welcome.


Please see the sample listed in Net::Server.


In addition to the command line arguments of the Net::Server base class, Net::Server::PreFork contains several other configurable parameters.

  Key               Value                   Default
  max_servers       \d+                     50
  max_requests      \d+                     1000
  serialize         (flock|semaphore|pipe)  undef
  # serialize defaults to flock on multi_port or on Solaris
  lock_file         "filename"              POSIX::tmpnam
  check_for_dead    \d+                     30
  max_dequeue       \d+                     undef
  check_for_dequeue \d+                     undef


The maximum number of child servers to start and maintain. This does not apply to dequeue processes.


The number of client connections to receive before a child terminates.


Determines whether the server serializes child connections. Options are undef, flock, semaphore, or pipe. Default is undef. On multi_port servers or on servers running on Solaris, the default is flock. The flock option uses blocking exclusive flock on the file specified in lock_file (see below). The semaphore option uses IPC::Semaphore (thanks to Bennett Todd) for giving some sample code. The pipe option reads on a pipe to choose the next. the flock option should be the most bulletproof while the pipe option should be the most portable. (Flock is able to reliquish the block if the process dies between accept on the socket and reading of the client connection − semaphore and pipe do not)


Filename to use in flock serialized accept in order to serialize the accept sequece between the children. This will default to a generated temporary filename. If default value is used the lock_file will be removed when the server closes.


Seconds to wait before checking to see if a child died without letting the parent know.


The maximum number of dequeue processes to start. If a value of zero or undef is given, no dequeue processes will be started. The number of running dequeue processes will be checked by the check_for_dead variable.


Seconds to wait before forking off a dequeue process. The run_dequeue hook must be defined when using this setting. It is intended to use the dequeue process to take care of items such as mail queues. If a value of undef is given, no dequeue processes will be started.


"Net::Server::PreFork" allows for the use of a configuration file to read in server parameters. The format of this conf file is simple key value pairs. Comments and white space are ignored.

  #−−−−−−−−−−−−−− file test.conf −−−−−−−−−−−−−−
  ### server information
  max_servers   80
  max_requests  1000
  ### user and group to become
  user        somebody
  group       everybody
  ### logging ?
  log_file    /var/log/server.log
  log_level   3
  pid_file    /tmp/
  ### access control
  allow       .+\.(net|com)
  allow       domain\.com
  deny        a.+
  ### background the process?
  background  1
  ### ports to bind
  port        localhost:20204
  port        20205
  ### reverse lookups ?
  # reverse_lookups on
  #−−−−−−−−−−−−−− file test.conf −−−−−−−−−−−−−−


Process flow follows Net::Server until the loop phase. At this point "max_servers" are forked and wait for connections. When a child accepts a connection, finishs processing a client, or exits, it relays that information to the parent, which keeps track and makes sure there are always "max_servers" running.


The PreForkSimple server has the following hooks in addition to the hooks provided by the Net::Server base class. See Net::Server

This hook occurs at the top of run_n_children which is called each time the server goes to start more child processes. This gives the parent to do a little of its own accountting (as desired). Idea for this hook came from James FitzGibbon.


This hook takes place immeditately after the child process forks from the parent and before the child begins accepting connections. It is intended for any addiotional chrooting or other security measures. It is suggested that all perl modules be used by this point, so that the most shared memory possible is used.


This hook takes place immediately before the child tells the parent that it is exiting. It is intended for saving out logged information or other general cleanup.


This hook only gets called in conjuction with the check_for_dequeue setting.


This hook is called in every pass through the main process wait loop.


Tests don’t seem to work on Win32. Any ideas or patches would be welcome.


See Net::Server


Paul T. Seamons


See Net::Server


Please see also Net::Server::Fork, Net::Server::INET, Net::Server::PreFork, Net::Server::MultiType, Net::Server::Single Net::Server::SIG Net::Server::Daemonize Net::Server::Proto


Personal Opportunity - Free software gives you access to billions of dollars of software at no cost. Use this software for your business, personal use or to develop a profitable skill. Access to source code provides access to a level of capabilities/information that companies protect though copyrights. Open source is a core component of the Internet and it is available to you. Leverage the billions of dollars in resources and capabilities to build a career, establish a business or change the world. The potential is endless for those who understand the opportunity.

Business Opportunity - Goldman Sachs, IBM and countless large corporations are leveraging open source to reduce costs, develop products and increase their bottom lines. Learn what these companies know about open source and how open source can give you the advantage.

Free Software

Free Software provides computer programs and capabilities at no cost but more importantly, it provides the freedom to run, edit, contribute to, and share the software. The importance of free software is a matter of access, not price. Software at no cost is a benefit but ownership rights to the software and source code is far more significant.

Free Office Software - The Libre Office suite provides top desktop productivity tools for free. This includes, a word processor, spreadsheet, presentation engine, drawing and flowcharting, database and math applications. Libre Office is available for Linux or Windows.

Free Books

The Free Books Library is a collection of thousands of the most popular public domain books in an online readable format. The collection includes great classical literature and more recent works where the U.S. copyright has expired. These books are yours to read and use without restrictions.

Source Code - Want to change a program or know how it works? Open Source provides the source code for its programs so that anyone can use, modify or learn how to write those programs themselves. Visit the GNU source code repositories to download the source.


Study at Harvard, Stanford or MIT - Open edX provides free online courses from Harvard, MIT, Columbia, UC Berkeley and other top Universities. Hundreds of courses for almost all major subjects and course levels. Open edx also offers some paid courses and selected certifications.

Linux Manual Pages - A man or manual page is a form of software documentation found on Linux/Unix operating systems. Topics covered include computer programs (including library and system calls), formal standards and conventions, and even abstract concepts.