{
    "mode": "perldoc",
    "parameter": "Net::Server::PreForkSimple",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Net%3A%3AServer%3A%3APreForkSimple/json",
    "generated": "2026-06-11T23:32:33Z",
    "synopsis": "use base qw(Net::Server::PreForkSimple);\nsub processrequest {\n#...code...\n}\nPACKAGE->run();",
    "sections": {
        "NAME": {
            "content": "Net::Server::PreForkSimple - Net::Server personality\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use base qw(Net::Server::PreForkSimple);\n\nsub processrequest {\n#...code...\n}\n\nPACKAGE->run();\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Please read the pod on Net::Server first. This module is a personality, or extension, or sub\nclass, of the Net::Server module.\n\nThis personality binds to one or more ports and then forks \"maxservers\" child processes. The\nserver will make sure that at any given time there are always \"maxservers\" available to receive\na client request. Each of these children will process up to \"maxrequests\" client connections.\nThis type is good for a heavily hit site that can keep \"maxservers\" processes dedicated to the\nserving. (Multi port accept defaults to using flock to serialize the children).\n\nAt this time, it does not appear that this module will pass tests on Win32 systems. Any ideas or\npatches for making the tests pass would be welcome.\n",
            "subsections": []
        },
        "SAMPLE CODE": {
            "content": "Please see the sample listed in Net::Server.\n",
            "subsections": []
        },
        "COMMAND LINE ARGUMENTS": {
            "content": "In addition to the command line arguments of the Net::Server base class, Net::Server::PreFork\ncontains several other configurable parameters.\n\nKey               Value                   Default\nmaxservers       \\d+                     50\nmaxrequests      \\d+                     1000\n\nserialize         (flock|semaphore\n|pipe|none)  undef\n# serialize defaults to flock on multiport or on Solaris\nlockfile         \"filename\"              File::Temp->new\n\ncheckfordead    \\d+                     30\n\nmaxdequeue       \\d+                     undef\ncheckfordequeue \\d+                     undef\n\nmaxservers\nThe maximum number of child servers to start and maintain. This does not apply to dequeue\nprocesses.\n\nmaxrequests\nThe number of client connections to receive before a child terminates.\n\nserialize\nDetermines whether the server serializes child connections. Options are undef, flock,\nsemaphore, pipe, or none. Default is undef. On multiport servers or on servers running on\nSolaris, the default is flock. The flock option uses blocking exclusive flock on the file\nspecified in *lockfile* (see below). The semaphore option uses IPC::Semaphore (thanks to\nBennett Todd) for giving some sample code. The pipe option reads on a pipe to choose the\nnext. the flock option should be the most bulletproof while the pipe option should be the\nmost portable. (Flock is able to relinquish the block if the process dies between accept on\nthe socket and reading of the client connection - semaphore and pipe do not). An option of\nnone will not perform any serialization. If \"none\" is passed and there are multiple ports\nthen a the default serialization will be used instead of \"none.\"\n\nlockfile\nFilename to use in flock serialized accept in order to serialize the accept sequence between\nthe children. This will default to a generated temporary filename. If default value is used\nthe lockfile will be removed when the server closes.\n\ncheckfordead\nSeconds to wait before checking to see if a child died without letting the parent know.\n\nmaxdequeue\nThe maximum number of dequeue processes to start. If a value of zero or undef is given, no\ndequeue processes will be started. The number of running dequeue processes will be checked\nby the checkfordead variable.\n\ncheckfordequeue\nSeconds to wait before forking off a dequeue process. The rundequeue hook must be defined\nwhen using this setting. It is intended to use the dequeue process to take care of items\nsuch as mail queues. If a value of undef is given, no dequeue processes will be started.\n",
            "subsections": []
        },
        "CONFIGURATION FILE": {
            "content": "\"Net::Server::PreFork\" allows for the use of a configuration file to read in server parameters.\nThe format of this conf file is simple key value pairs. Comments and white space are ignored.\n\n#-------------- file test.conf --------------\n\n### server information\nmaxservers   80\n\nmaxrequests  1000\n\n### user and group to become\nuser        somebody\ngroup       everybody\n\n### logging ?\nlogfile    /var/log/server.log\nloglevel   3\npidfile    /tmp/server.pid\n\n### access control\nallow       .+\\.(net|com)\nallow       domain\\.com\ndeny        a.+\n\n### background the process?\nbackground  1\n\n### ports to bind\nhost        127.0.0.1\nport        localhost:20204\nport        20205\n\n### reverse lookups ?\n# reverselookups on\n\n#-------------- file test.conf --------------\n",
            "subsections": []
        },
        "PROCESS FLOW": {
            "content": "Process flow follows Net::Server until the loop phase. At this point \"maxservers\" are forked\nand wait for connections. When a child accepts a connection, finishes processing a client, or\nexits, it relays that information to the parent, which keeps track and makes sure there are\nalways \"maxservers\" running.\n",
            "subsections": []
        },
        "HOOKS": {
            "content": "The PreForkSimple server has the following hooks in addition to the hooks provided by the\nNet::Server base class. See Net::Server\n\n\"$self->runnchildrenhook()\"\nThis hook occurs at the top of runnchildren which is called each time the server goes to\nstart more child processes. This gives the parent to do a little of its own accounting (as\ndesired). Idea for this hook came from James FitzGibbon.\n\n\"$self->childinithook()\"\nThis hook takes place immediately after the child process forks from the parent and before\nthe child begins accepting connections. It is intended for any additional chrooting or other\nsecurity measures. It is suggested that all perl modules be used by this point, so that the\nmost shared memory possible is used.\n\n\"$self->childfinishhook()\"\nThis hook takes place immediately before the child tells the parent that it is exiting. It\nis intended for saving out logged information or other general cleanup.\n\n\"$self->rundequeue()\"\nThis hook only gets called in conjunction with the checkfordequeue setting.\n\n\"$self->idleloophook()\"\nThis hook is called in every pass through the main process wait loop.\n",
            "subsections": []
        },
        "HOT DEPLOY": {
            "content": "Since version 2.000, the PreForkSimple server has accepted the TTIN and TTOU signals. When a\nTTIN is received, the maxservers is increased by 1. If a TTOU signal is received the\nmaxservers is decreased by 1. This allows for adjusting the number of handling processes\nwithout having to restart the server.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Tests don't seem to work on Win32. Any ideas or patches would be welcome.\n",
            "subsections": []
        },
        "TO DO": {
            "content": "See Net::Server\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Paul T. Seamons paul@seamons.com\n",
            "subsections": []
        },
        "THANKS": {
            "content": "See Net::Server\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Please see also Net::Server::Fork, Net::Server::INET, Net::Server::PreFork,\nNet::Server::MultiType, Net::Server::Single Net::Server::SIG Net::Server::Daemonize\nNet::Server::Proto\n",
            "subsections": []
        }
    },
    "summary": "Net::Server::PreForkSimple - Net::Server personality",
    "flags": [],
    "examples": [],
    "see_also": []
}