{
    "mode": "perldoc",
    "parameter": "CGI::Fast",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/CGI%3A%3AFast/json",
    "generated": "2026-06-09T18:09:15Z",
    "synopsis": "use CGI::Fast\nsocketpath  => '9000',\nsocketperm  => 0777,\nlistenqueue => 50;\nuse CGI qw/ :standard /;\n$COUNTER = 0;\n# optional, will default to STDOUT, STDERR\nCGI::Fast->filehandles({\nfcgioutputfilehandle => IO::Handle->new,\nfcgierrorfilehandle  => IO::Handle->new,\n});\nwhile ($q = CGI::Fast->new) {\nprocessrequest($q);\n}",
    "sections": {
        "NAME": {
            "content": "CGI::Fast - CGI Interface for Fast CGI\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use CGI::Fast\nsocketpath  => '9000',\nsocketperm  => 0777,\nlistenqueue => 50;\n\nuse CGI qw/ :standard /;\n\n$COUNTER = 0;\n\n# optional, will default to STDOUT, STDERR\nCGI::Fast->filehandles({\nfcgioutputfilehandle => IO::Handle->new,\nfcgierrorfilehandle  => IO::Handle->new,\n});\n\nwhile ($q = CGI::Fast->new) {\nprocessrequest($q);\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "CGI::Fast is a subclass of the CGI object created by CGI.pm. It is specialized to work with the\nFCGI module, which greatly speeds up CGI scripts by turning them into persistently running\nserver processes. Scripts that perform time-consuming initialization processes, such as loading\nlarge modules or opening persistent database connections, will see large performance\nimprovements.\n\nNote that as CGI::Fast is based on CGI.pm it is no longer advised as a way to write Perl web\napps. See <https://metacpan.org/pod/CGI#CGI.pm-HAS-BEEN-REMOVED-FROM-THE-PERL-CORE> for more\ninformation about this\n",
            "subsections": []
        },
        "OTHER PIECES OF THE PUZZLE": {
            "content": "In order to use CGI::Fast you'll need the FCGI module. See http://www.cpan.org/ for details.\n",
            "subsections": []
        },
        "WRITING FASTCGI PERL SCRIPTS": {
            "content": "FastCGI scripts are persistent: one or more copies of the script are started up when the server\ninitializes, and stay around until the server exits or they die a natural death. After\nperforming whatever one-time initialization it needs, the script enters a loop waiting for\nincoming connections, processing the request, and waiting some more.\n\nA typical FastCGI script will look like this:\n\n#!perl\nuse CGI::Fast;\ndosomeinitialization();\nwhile ($q = CGI::Fast->new) {\nprocessrequest($q);\n}\n\nEach time there's a new request, CGI::Fast returns a CGI object to your loop. The rest of the\ntime your script waits in the call to new(). When the server requests that your script be\nterminated, new() will return undef. You can of course exit earlier if you choose. A new version\nof the script will be respawned to take its place (this may be necessary in order to avoid Perl\nmemory leaks in long-running scripts).\n\nCGI.pm's default CGI object mode also works. Just modify the loop this way:\n\nwhile (CGI::Fast->new) {\nprocessrequest();\n}\n\nCalls to header(), startform(), etc. will all operate on the current request.\n",
            "subsections": []
        },
        "INSTALLING FASTCGI SCRIPTS": {
            "content": "See the FastCGI developer's kit documentation for full details. On the Apache server, the\nfollowing line must be added to srm.conf:\n\nAddType application/x-httpd-fcgi .fcgi\n\nFastCGI scripts must end in the extension .fcgi. For each script you install, you must add\nsomething like the following to srm.conf:\n\nFastCgiServer /usr/lib/cgi-bin/fileupload.fcgi -processes 2\n\nThis instructs Apache to launch two copies of fileupload.fcgi at startup time.\n",
            "subsections": []
        },
        "USING FASTCGI SCRIPTS AS CGI SCRIPTS": {
            "content": "Any script that works correctly as a FastCGI script will also work correctly when installed as a\nvanilla CGI script. However it will not see any performance benefit.\n",
            "subsections": []
        },
        "EXTERNAL FASTCGI SERVER INVOCATION": {
            "content": "FastCGI supports a TCP/IP transport mechanism which allows FastCGI scripts to run external to\nthe webserver, perhaps on a remote machine. To configure the webserver to connect to an external\nFastCGI server, you would add the following to your srm.conf:\n\nFastCgiExternalServer /usr/lib/cgi-bin/fileupload.fcgi -host sputnik:8888\n\nTwo environment variables affect how the \"CGI::Fast\" object is created, allowing \"CGI::Fast\" to\nbe used as an external FastCGI server. (See \"FCGI\" documentation for \"FCGI::OpenSocket\" for more\ninformation.)\n\nYou can set these as ENV variables or imports in the use CGI::Fast statement. If the ENV\nvariables are set then these will be favoured so you can override the import statements on the\ncommand line, etc.\n\nFCGISOCKETPATH / socketpath\nThe address (TCP/IP) or path (UNIX Domain) of the socket the external FastCGI script to\nwhich bind an listen for incoming connections from the web server.\n\nFCGISOCKETPERM / socketperm\nPermissions for UNIX Domain socket.\n\nFCGILISTENQUEUE / listenqueue\nMaximum length of the queue of pending connections, defaults to 100.\n\nFor example:\n\nuse CGI::Fast\nsocketpath  => \"sputnik:8888\",\nlistenqueue => \"50\"\n;\n\nuse CGI qw/ :standard /;\n\ndosomeinitialization();\n\nwhile ($q = CGI::Fast->new) {\nprocessrequest($q);\n}\n\nOr:\n\nuse CGI::Fast;\nuse CGI qw/ :standard /;\n\ndosomeinitialization();\n\n$ENV{FCGISOCKETPATH} = \"sputnik:8888\";\n$ENV{FCGILISTENQUEUE} = 50;\n\nwhile ($q = CGI::Fast->new) {\nprocessrequest($q);\n}\n\nNote the importance of having use CGI after use CGI::Fast as this will prevent any CGI import\npragmas being overwritten by CGI::Fast. You can use CGI::Fast as a drop in replacement like so:\n\nuse CGI::Fast qw/ :standard /\n",
            "subsections": []
        },
        "FILE HANDLES": {
            "content": "FCGI defaults to using STDOUT and STDERR as its output filehandles - this may lead to unexpected\nredirect of output if you migrate scripts from CGI.pm to CGI::Fast. To get around this you can\nuse the filehandles method, which you must do before the first call to CGI::Fast->new. For\nexample using IO::Handle:\n\nCGI::Fast->filehandles({\nfcgioutputfilehandle => IO::Handle->new,\nfcgierrorfilehandle  => IO::Handle->new,\n});\n\nwhile (CGI::Fast->new) {\n..\n}\n\nOverriding STDIN using the \"fcgiinputfilehandle\" key is also possible, however doing so is\nlikely to break at least POST requests.\n",
            "subsections": []
        },
        "CAVEATS": {
            "content": "I haven't tested this very much.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyright 1996-1998, Lincoln D. Stein. All rights reserved. Currently maintained by Lee Johnson\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nAddress bug reports and comments to:\n\nhttps://github.com/leejo/cgi-fast\n",
            "subsections": []
        },
        "BUGS": {
            "content": "This section intentionally left blank.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CGI::Carp, CGI\n",
            "subsections": []
        }
    },
    "summary": "CGI::Fast - CGI Interface for Fast CGI",
    "flags": [],
    "examples": [],
    "see_also": []
}