There are three steps in CGI processing,
- Initialization
- Processing
- Termination.
Initialization :
Script determines the input, environment and state. Each time it acts like as it was invoked for the first time. The method of Invoking script can be determined using Request_Method variable.
The input can be retrieved using the following variables.
- If request method is GET, Query_STRING variable can be used to determine the input.
- If request method is POST, STDIN and CONTENT_LENGTH variable can be used to determine the input.
Processing:
Processing phase is further divided into 2 phases or steps.
Processing Input data:
Transform the data which differentates it from all other CGI programs.
Output the results:
Output is usually a header and some html in case of simple CGI scipts. More complex scripts, output graphics, graphics with text etc.
Termination :
- Termination refers to cleaning up resources after processing and quitting.
- All files, memory allocated must be freed or releases for other useful purpose. Failure to do this will report an error.
- An error exit routine can be used to check whether the script resources are cleaned up as thoroughly as possible.
