---
name: "FCGI_Accept"
section: "3"
platform: "linux"
package: "fcgi"
version: "2.4.7-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/FCGI_Accept"
---

# FCGI\_Accept(3)

NAME\
      FCGI\_Accept, FCGI\_ToFILE, FCGI\_ToFcgiStream\
          \- fcgi\_stdio compatibility library

SYNOPSIS\
      \#include "fcgi\_stdio.h"

     int\
      FCGI\_Accept(void);

     FILE \*\
      FCGI\_ToFILE(FCGI\_FILE \*);

     FCGI\_Stream \*\
      FCGI\_ToFcgiStream(FCGI\_FILE \*);

DESCRIPTION\
      The FCGI\_Accept function accepts a new request from the HTTP server\
      and creates a CGI-compatible execution environment for the request.

     If the application was invoked as a CGI program, the first\
      call to FCGI\_Accept is essentially a no-op and the second\
      call returns -1.  This causes a correctly coded FastCGI Responder\
      application to run a single request and exit, giving CGI\
      behavior.

     If the application was invoked as a FastCGI server, the first\
      call to FCGI\_Accept indicates that the application has completed\
      its initialization and is ready to accept its first request.\
      Subsequent calls to FCGI\_Accept indicate that the application has\
      completed processing its current request and is ready to accept a\
      new request.  An application can complete the current request\
      without accepting a new one by calling [FCGI\_Finish(3)](/FCGI_Finish/3.md); later, when\
      ready to accept a new request, the application calls FCGI\_Accept.

     In completing the current request, FCGI\_Accept may detect\
      errors, e.g. a broken pipe to a client who has disconnected\
      early.  FCGI\_Accept ignores such errors.  An application\
      that wishes to handle such errors should explicitly call\
      fclose(stderr), then fclose(stdout); an EOF return from\
      either one indicates an error.

     If the environment variable FCGI\_WEB\_SERVER\_ADDRS is set when\
      FCGI\_Accept is called, it should contain a comma-separated list\
      of IP addresses.  Each IP address is written as four decimal\
      numbers in the range \[0..255\] separated by decimal points.\
      ([nslookup(8)](/nslookup/8.md) translates the more familiar symbolic IP hostname\
      into this form.)  So one legal binding for this variable is

         FCGI\_WEB\_SERVER\_ADDRS=199.170.183.28,199.170.183.71

     FCGI\_Accept checks the peer IP address of each new connection for\
      membership in the list.  If the check fails (including the\
      possibility that the connection didn't use TCP/IP transport),\
      FCGI\_Accept closes the connection and accepts another one\
      (without returning in between).

     After accepting a new request, FCGI\_Accept assigns new values\
      to the global variables stdin, stdout, stderr, and environ.\
      After FCGI\_Accept returns, these variables have the same\
      interpretation as on entry to a CGI program.

     FCGI\_Accept frees any storage allocated by the previous call\
      to FCGI\_Accept.  This has important consequences:

         DO NOT retain pointers to the environ array or any strings\
          contained in it (e.g. to the result of calling [getenv(3)](/getenv/3.md)),\
          since these will be freed by the next call to FCGI\_Finish or\
          FCGI\_Accept.

         DO NOT use [setenv(3)](/setenv/3.md) or [putenv(3)](/putenv/3.md) to modify the environ array\
          created by FCGI\_Accept, since this will either leak storage\
          or cause the next call to FCGI\_Finish or FCGI\_Accept to free\
          storage that should not be freed.

         If your application needs to use setenv or putenv to modify\
          the environ array, it should follow this coding pattern:

             char \*\*savedEnviron, \*\*requestEnviron;\
              int acceptStatus;

             savedEnviron = environ;\
              acceptStatus = FCGI\_Accept();\
              requestEnviron = environ;\
              environ = savedEnviron;\
              if(acceptStatus \>= 0 && !FCGX\_IsCGI()) {\
                  /\*\
                   \* requestEnviron points to name-value pairs in\
                   \* storage allocated by FCGI\_Accept.  OK to read,\
                   \* not OK to retain pointers -- make copies instead.\
                   \*/\
              }\
              /\*\
               \* OK to do setenv or putenv, but beware of storage leaks!\
               \*/

     In addition to the standard CGI environment variables, the\
      environment variable FCGI\_ROLE is always set to the role\
      of the current request.  The roles currently defined are\
      RESPONDER, AUTHORIZER, and FILTER.

     In the FILTER role, the additional variables FCGI\_DATA\_LENGTH\
      and FCGI\_DATA\_LAST\_MOD are also defined.  See the manpage\
      [FCGI\_StartFilterData(3)](/FCGI_StartFilterData/3.md) for complete information.

     The macros FCGI\_ToFILE and FCGI\_ToFcgiStream are provided\
      to allow escape to native functions that use the types FILE or\
      FCGI\_Stream.  In the case of FILE, functions would have to\
      be separately compiled, since fcgi\_stdio.h replaces the standard\
      FILE with FCGI\_FILE.

RETURN VALUES\
      0 for successful call, -1 for error (application should exit).

SEE ALSO\
      [FCGI\_Finish(3)](/FCGI_Finish/3.md)\
      [FCGI\_StartFilterData(3)](/FCGI_StartFilterData/3.md)\
      [FCGI\_SetExitStatus(3)](/FCGI_SetExitStatus/3.md)\
      [cgi-fcgi(1)](/cgi-fcgi/1.md)\
      [nslookup(8)](/nslookup/8.md)

HISTORY\
      Copyright (c) 1996 Open Market, Inc.\
      See the file "LICENSE" for information on usage and redistribution\
      of this file, and for a DISCLAIMER OF ALL WARRANTIES.\
      $Id: FCGI\_Accept.3,v 1.1.1.1 1997/09/16 15:36:25 stanleyg Exp $
