<s>
In	O
computing	O
,	O
Common	B-Language
Gateway	I-Language
Interface	I-Language
(	O
CGI	O
)	O
is	O
an	O
interface	O
specification	O
that	O
enables	O
web	B-Application
servers	I-Application
to	O
execute	O
an	O
external	O
program	O
,	O
typically	O
to	O
process	B-Operating_System
user	O
requests	O
.	O
</s>
<s>
Such	O
programs	O
are	O
often	O
written	O
in	O
a	O
scripting	B-Language
language	I-Language
and	O
are	O
commonly	O
referred	O
to	O
as	O
CGI	B-Language
scripts	I-Language
,	O
but	O
they	O
may	O
include	O
compiled	B-Language
programs	O
.	O
</s>
<s>
A	O
typical	O
use	O
case	O
occurs	O
when	O
a	O
web	O
user	O
submits	O
a	O
web	B-General_Concept
form	I-General_Concept
on	O
a	O
web	O
page	O
that	O
uses	O
CGI	O
.	O
</s>
<s>
The	O
form	B-General_Concept
's	O
data	O
is	O
sent	O
to	O
the	O
web	B-Application
server	I-Application
within	O
an	O
HTTP	B-Protocol
request	O
with	O
a	O
URL	O
denoting	O
a	O
CGI	B-Language
script	I-Language
.	O
</s>
<s>
The	O
web	B-Application
server	I-Application
then	O
launches	O
the	O
CGI	B-Language
script	I-Language
in	O
a	O
new	O
computer	B-Operating_System
process	I-Operating_System
,	O
passing	O
the	O
form	B-General_Concept
data	O
to	O
it	O
.	O
</s>
<s>
The	O
output	O
of	O
the	O
CGI	B-Language
script	I-Language
,	O
usually	O
in	O
the	O
form	B-General_Concept
of	O
HTML	B-Language
,	O
is	O
returned	O
by	O
the	O
script	O
to	O
the	O
Web	B-Application
server	I-Application
,	O
and	O
the	O
server	O
relays	O
it	O
back	O
to	O
the	O
browser	B-Application
as	O
its	O
response	O
to	O
the	O
browser	B-Application
's	O
request	O
.	O
</s>
<s>
In	O
1993	O
,	O
the	O
National	B-General_Concept
Center	I-General_Concept
for	I-General_Concept
Supercomputing	I-General_Concept
Applications	I-General_Concept
(	O
NCSA	O
)	O
team	O
wrote	O
the	O
specification	O
for	O
calling	O
command	O
line	O
executables	O
on	O
the	O
www-talk	O
mailing	O
list	O
.	O
</s>
<s>
The	O
other	O
Web	B-Application
server	I-Application
developers	O
adopted	O
it	O
,	O
and	O
it	O
has	O
been	O
a	O
standard	O
for	O
Web	B-Application
servers	I-Application
ever	O
since	O
.	O
</s>
<s>
This	O
work	O
resulted	O
in	O
RFC	B-Language
3875	I-Language
,	O
which	O
specified	O
CGI	O
Version	O
1.1	O
.	O
</s>
<s>
Historically	O
CGI	O
programs	O
were	O
often	O
written	O
using	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
RFC	B-Language
3875	I-Language
"	O
The	O
Common	B-Language
Gateway	I-Language
Interface	I-Language
(	O
CGI	O
)	O
"	O
partially	O
defines	O
CGI	O
using	O
C	B-Language
,	O
in	O
saying	O
that	O
environment	O
variables	O
"	O
are	O
accessed	O
by	O
the	O
C	B-Language
library	I-Language
routine	O
getenv( )	O
or	O
variable	O
environ	O
"	O
.	O
</s>
<s>
The	O
name	O
CGI	O
comes	O
from	O
the	O
early	O
days	O
of	O
the	O
Web	O
,	O
where	O
webmasters	O
wanted	O
to	O
connect	O
legacy	O
information	O
systems	O
such	O
as	O
databases	O
to	O
their	O
Web	B-Application
servers	I-Application
.	O
</s>
<s>
The	O
CGI	O
program	O
was	O
executed	O
by	O
the	O
server	O
that	O
provided	O
a	O
common	O
"	O
gateway	O
"	O
between	O
the	O
Web	B-Application
server	I-Application
and	O
the	O
legacy	O
information	O
system	O
.	O
</s>
<s>
Each	O
Web	B-Application
server	I-Application
runs	O
HTTP	B-Application
server	I-Application
software	O
,	O
which	O
responds	O
to	O
requests	O
from	O
web	B-Application
browsers	I-Application
.	O
</s>
<s>
Generally	O
,	O
the	O
HTTP	B-Application
server	I-Application
has	O
a	O
directory	B-Application
(	O
folder	O
)	O
,	O
which	O
is	O
designated	O
as	O
a	O
document	O
collection	O
–	O
files	O
that	O
can	O
be	O
sent	O
to	O
Web	B-Application
browsers	I-Application
connected	O
to	O
this	O
server	O
.	O
</s>
<s>
For	O
example	O
,	O
if	O
the	O
Web	B-Application
server	I-Application
has	O
the	O
domain	O
name	O
example.com,	O
and	O
its	O
document	O
collection	O
is	O
stored	O
at	O
/usr/local/apache/htdocs/	O
in	O
the	O
local	O
file	O
system	O
,	O
then	O
the	O
Web	B-Application
server	I-Application
will	O
respond	O
to	O
a	O
request	O
for	O
http://example.com/index.html	O
by	O
sending	O
to	O
the	O
browser	B-Application
the	O
(	O
pre-written	O
)	O
file	O
/usr/local/apache/htdocs/index.html	O
.	O
</s>
<s>
For	O
pages	O
constructed	O
on	O
the	O
fly	O
,	O
the	O
server	O
software	O
may	O
defer	O
requests	O
to	O
separate	O
programs	O
and	O
relay	O
the	O
results	O
to	O
the	O
requesting	O
client	O
(	O
usually	O
,	O
a	O
Web	B-Application
browser	I-Application
that	O
displays	O
the	O
page	O
to	O
the	O
end	O
user	O
)	O
.	O
</s>
<s>
In	O
the	O
early	O
days	O
of	O
the	O
Web	O
,	O
such	O
programs	O
were	O
usually	O
small	O
and	O
written	O
in	O
a	O
scripting	B-Language
language	I-Language
;	O
hence	O
,	O
they	O
were	O
known	O
as	O
scripts	O
.	O
</s>
<s>
HTTP	B-Protocol
provides	O
ways	O
for	O
browsers	B-Application
to	O
pass	O
such	O
information	O
to	O
the	O
Web	B-Application
server	I-Application
,	O
e.g.	O
</s>
<s>
Conversely	O
,	O
upon	O
returning	O
,	O
the	O
script	O
must	O
provide	O
all	O
the	O
information	O
required	O
by	O
HTTP	B-Protocol
for	O
a	O
response	O
to	O
the	O
request	O
:	O
the	O
HTTP	B-Protocol
status	O
of	O
the	O
request	O
,	O
the	O
document	O
content	O
(	O
if	O
available	O
)	O
,	O
the	O
document	O
type	O
(	O
e.g.	O
</s>
<s>
HTML	B-Language
,	O
PDF	O
,	O
or	O
plain	O
text	O
)	O
,	O
et	O
cetera	O
.	O
</s>
<s>
Therefore	O
,	O
it	O
was	O
decided	O
to	O
specify	O
a	O
way	O
for	O
exchanging	O
this	O
information	O
:	O
CGI	O
(	O
the	O
Common	B-Language
Gateway	I-Language
Interface	I-Language
,	O
as	O
it	O
defines	O
a	O
common	O
way	O
for	O
server	O
software	O
to	O
interface	O
with	O
scripts	O
)	O
.	O
</s>
<s>
Webpage	O
generating	O
programs	O
invoked	O
by	O
server	O
software	O
that	O
operate	O
according	O
to	O
the	O
CGI	O
specification	O
are	O
known	O
as	O
CGI	B-Language
scripts	I-Language
.	O
</s>
<s>
This	O
specification	O
was	O
quickly	O
adopted	O
and	O
is	O
still	O
supported	O
by	O
all	O
well-known	O
server	O
software	O
,	O
such	O
as	O
Apache	B-Application
,	O
IIS	B-Application
,	O
and	O
(	O
with	O
an	O
extension	O
)	O
node.js-based	O
servers	O
.	O
</s>
<s>
An	O
early	O
use	O
of	O
CGI	B-Language
scripts	I-Language
was	O
to	O
process	B-Operating_System
forms	O
.	O
</s>
<s>
In	O
the	O
beginning	O
of	O
HTML	B-Language
,	O
HTML	B-General_Concept
forms	I-General_Concept
typically	O
had	O
an	O
"	O
action	O
"	O
attribute	O
and	O
a	O
button	O
designated	O
as	O
the	O
"	O
submit	O
"	O
button	O
.	O
</s>
<s>
When	O
the	O
submit	O
button	O
is	O
pushed	O
the	O
URI	O
specified	O
in	O
the	O
"	O
action	O
"	O
attribute	O
would	O
be	O
sent	O
to	O
the	O
server	O
with	O
the	O
data	O
from	O
the	O
form	B-General_Concept
sent	O
as	O
a	O
query	B-Protocol
string	I-Protocol
.	O
</s>
<s>
If	O
the	O
"	O
action	O
"	O
specifies	O
a	O
CGI	B-Language
script	I-Language
then	O
the	O
CGI	B-Language
script	I-Language
would	O
be	O
executed	O
and	O
it	O
then	O
produces	O
an	O
HTML	B-Language
page	O
.	O
</s>
<s>
A	O
Web	B-Application
server	I-Application
allows	O
its	O
owner	O
to	O
configure	O
which	O
URLs	O
shall	O
be	O
handled	O
by	O
which	O
CGI	B-Language
scripts	I-Language
.	O
</s>
<s>
This	O
is	O
usually	O
done	O
by	O
marking	O
a	O
new	O
directory	B-Application
within	O
the	O
document	O
collection	O
as	O
containing	O
CGI	B-Language
scripts	I-Language
–	O
its	O
name	O
is	O
often	O
cgi-bin	B-Language
.	O
</s>
<s>
For	O
example	O
,	O
/usr/local/apache/htdocs/cgi	O
-bin	O
could	O
be	O
designated	O
as	O
a	O
CGI	O
directory	B-Application
on	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
When	O
a	O
Web	B-Application
browser	I-Application
requests	O
a	O
URL	O
that	O
points	O
to	O
a	O
file	O
within	O
the	O
CGI	O
directory	B-Application
(	O
e.g.	O
,	O
http://example.com/cgi-bin/printenv.pl/with/additional/path?and=a&query=string	O
)	O
,	O
then	O
,	O
instead	O
of	O
simply	O
sending	O
that	O
file	O
(	O
/usr/local/apache/htdocs/cgi-bin/printenv.pl	O
)	O
to	O
the	O
Web	B-Application
browser	I-Application
,	O
the	O
HTTP	B-Application
server	I-Application
runs	O
the	O
specified	O
script	O
and	O
passes	O
the	O
output	O
of	O
the	O
script	O
to	O
the	O
Web	B-Application
browser	I-Application
.	O
</s>
<s>
That	O
is	O
,	O
anything	O
that	O
the	O
script	O
sends	O
to	O
standard	O
output	O
is	O
passed	O
to	O
the	O
Web	B-Application
client	I-Application
instead	O
of	O
being	O
shown	O
on-screen	O
in	O
a	O
terminal	O
window	O
.	O
</s>
<s>
For	O
instance	O
,	O
if	O
a	O
slash	O
and	O
additional	O
directory	B-Application
name(s )	O
are	O
appended	O
to	O
the	O
URL	O
immediately	O
after	O
the	O
name	O
of	O
the	O
script	O
(	O
in	O
this	O
example	O
,	O
/with/additional/path	O
)	O
,	O
then	O
that	O
path	O
is	O
stored	O
in	O
the	O
PATH_INFO	O
environment	O
variable	O
before	O
the	O
script	O
is	O
called	O
.	O
</s>
<s>
If	O
parameters	O
are	O
sent	O
to	O
the	O
script	O
via	O
an	O
HTTP	B-Protocol
GET	O
request	O
(	O
a	O
question	O
mark	O
appended	O
to	O
the	O
URL	O
,	O
followed	O
by	O
param	O
=	O
value	O
pairs	O
;	O
in	O
the	O
example	O
,	O
?	O
and	O
=	O
a&query	O
=	O
string	O
)	O
,	O
then	O
those	O
parameters	O
are	O
stored	O
in	O
the	O
QUERY_STRING	O
environment	O
variable	O
before	O
the	O
script	O
is	O
called	O
.	O
</s>
<s>
If	O
parameters	O
are	O
sent	O
to	O
the	O
script	O
via	O
an	O
HTTP	B-Protocol
POST	I-Protocol
request	I-Protocol
,	O
they	O
are	O
passed	O
to	O
the	O
script	O
's	O
standard	O
input	O
.	O
</s>
<s>
The	O
script	O
can	O
then	O
read	O
these	O
environment	O
variables	O
or	O
data	O
from	O
standard	O
input	O
and	O
adapt	O
to	O
the	O
Web	B-Application
browser	I-Application
's	O
request	O
.	O
</s>
<s>
The	O
following	O
Perl	B-Language
program	O
shows	O
all	O
the	O
environment	O
variables	O
passed	O
by	O
the	O
Web	B-Application
server	I-Application
:	O
</s>
<s>
If	O
a	O
Web	B-Application
browser	I-Application
issues	O
a	O
request	O
for	O
the	O
environment	O
variables	O
at	O
http://example.com/cgi-bin/printenv.pl/foo/bar?var1=value1&var2=with%20percent%20encoding	O
,	O
a	O
64-bit	O
Windows	B-Device
7	I-Device
Web	B-Application
server	I-Application
running	O
cygwin	B-Language
returns	O
the	O
following	O
information	O
:	O
</s>
<s>
Some	O
,	O
such	O
as	O
PATH_INFO	O
,	O
QUERY_STRING	O
,	O
and	O
the	O
ones	O
starting	O
with	O
HTTP_	O
,	O
pass	O
information	O
along	O
from	O
the	O
HTTP	B-Protocol
request	O
.	O
</s>
<s>
From	O
the	O
environment	O
,	O
it	O
can	O
be	O
seen	O
that	O
the	O
Web	B-Application
browser	I-Application
is	O
Firefox	B-Application
running	O
on	O
a	O
Windows	B-Device
7	I-Device
PC	O
,	O
the	O
Web	B-Application
server	I-Application
is	O
Apache	B-Application
running	O
on	O
a	O
system	O
that	O
emulates	O
Unix	B-Application
,	O
and	O
the	O
CGI	B-Language
script	I-Language
is	O
named	O
cgi-bin/printenv.pl	O
.	O
</s>
<s>
The	O
program	O
could	O
then	O
generate	O
any	O
content	O
,	O
write	O
that	O
to	O
standard	O
output	O
,	O
and	O
the	O
Web	B-Application
server	I-Application
will	O
transmit	O
it	O
to	O
the	O
browser	B-Application
.	O
</s>
<s>
SERVER_SOFTWARE	O
:	O
name/version	O
of	O
HTTP	B-Application
server	I-Application
.	O
</s>
<s>
SERVER_NAME	O
:	O
host	B-Protocol
name	I-Protocol
of	O
the	O
server	O
,	O
may	O
be	O
dot-decimal	B-Protocol
IP	B-Protocol
address	I-Protocol
.	O
</s>
<s>
SERVER_PROTOCOL	O
:	O
HTTP/version	O
.	O
</s>
<s>
SERVER_PORT	O
:	O
TCP	B-Protocol
port	I-Protocol
(	O
decimal	O
)	O
.	O
</s>
<s>
REQUEST_METHOD	O
:	O
name	O
of	O
HTTP	B-Protocol
method	O
(	O
see	O
above	O
)	O
.	O
</s>
<s>
PATH_TRANSLATED	O
:	O
corresponding	O
full	B-Application
path	I-Application
as	O
supposed	O
by	O
server	O
,	O
if	O
PATH_INFO	O
is	O
present	O
.	O
</s>
<s>
SCRIPT_NAME	O
:	O
relative	O
path	O
to	O
the	O
program	O
,	O
like	O
/cgi-bin/script.cgi	O
.	O
</s>
<s>
The	O
query	B-Protocol
string	I-Protocol
may	O
be	O
composed	O
of	O
*	O
name	O
=	O
value	O
pairs	O
separated	O
with	O
ampersands	O
(	O
such	O
as	O
var1	O
=	O
val1&var2	O
=	O
val2	O
...	O
)	O
when	O
used	O
to	O
submit	O
form	B-General_Concept
data	O
transferred	O
via	O
GET	O
method	O
as	O
defined	O
by	O
HTML	B-Language
application/x	O
-www-form-urlencoded	O
.	O
</s>
<s>
REMOTE_HOST	O
:	O
host	B-Protocol
name	I-Protocol
of	O
the	O
client	O
,	O
unset	O
if	O
server	O
did	O
not	O
perform	O
such	O
lookup	O
.	O
</s>
<s>
REMOTE_ADDR	O
:	O
IP	B-Protocol
address	I-Protocol
of	O
the	O
client	O
(	O
dot-decimal	B-Protocol
)	O
.	O
</s>
<s>
CONTENT_TYPE	O
:	O
Internet	B-Application
media	I-Application
type	I-Application
of	O
input	O
data	O
if	O
PUT	O
or	O
POST	O
method	O
are	O
used	O
,	O
as	O
provided	O
via	O
HTTP	B-Protocol
header	I-Protocol
.	O
</s>
<s>
CONTENT_LENGTH	O
:	O
similarly	O
,	O
size	O
of	O
input	O
data	O
(	O
decimal	O
,	O
in	O
octets	O
)	O
if	O
provided	O
via	O
HTTP	B-Protocol
header	I-Protocol
.	O
</s>
<s>
Variables	O
passed	O
by	O
user	O
agent	O
(	O
HTTP_ACCEPT	O
,	O
HTTP_ACCEPT_LANGUAGE	O
,	O
HTTP_USER_AGENT	O
,	O
HTTP_COOKIE	O
and	O
possibly	O
others	O
)	O
contain	O
values	O
of	O
corresponding	O
HTTP	B-Protocol
headers	I-Protocol
and	O
therefore	O
have	O
the	O
same	O
sense	O
.	O
</s>
<s>
The	O
program	O
returns	O
the	O
result	O
to	O
the	O
Web	B-Application
server	I-Application
in	O
the	O
form	B-General_Concept
of	O
standard	O
output	O
,	O
beginning	O
with	O
a	O
header	O
and	O
a	O
blank	B-General_Concept
line	I-General_Concept
.	O
</s>
<s>
The	O
header	O
is	O
encoded	O
in	O
the	O
same	O
way	O
as	O
an	O
HTTP	B-Protocol
header	I-Protocol
and	O
must	O
include	O
the	O
MIME	B-Application
type	I-Application
of	O
the	O
document	O
returned	O
.	O
</s>
<s>
The	O
headers	O
,	O
supplemented	O
by	O
the	O
Web	B-Application
server	I-Application
,	O
are	O
generally	O
forwarded	O
with	O
the	O
response	O
back	O
to	O
the	O
user	O
.	O
</s>
<s>
Here	O
is	O
a	O
simple	O
CGI	O
program	O
written	O
in	O
Python	B-Language
3	O
along	O
with	O
the	O
HTML	B-Language
that	O
handles	O
a	O
simple	O
addition	O
problem	O
.	O
</s>
<s>
add.html	O
:	O
</s>
<s>
This	O
Python	B-Language
3	O
CGI	O
program	O
gets	O
the	O
inputs	O
from	O
the	O
HTML	B-Language
and	O
adds	O
the	O
two	O
numbers	O
together	O
.	O
</s>
<s>
A	O
Web	B-Application
server	I-Application
that	O
supports	O
CGI	O
can	O
be	O
configured	O
to	O
interpret	O
a	O
URL	O
that	O
it	O
serves	O
as	O
a	O
reference	O
to	O
a	O
CGI	B-Language
script	I-Language
.	O
</s>
<s>
A	O
common	O
convention	O
is	O
to	O
have	O
a	O
cgi-bin/	B-Language
directory	B-Application
at	O
the	O
base	O
of	O
the	O
directory	B-Application
tree	I-Application
and	O
treat	O
all	O
executable	O
files	O
within	O
this	O
directory	B-Application
(	O
and	O
no	O
other	O
,	O
for	O
security	O
)	O
as	O
CGI	B-Language
scripts	I-Language
.	O
</s>
<s>
Another	O
popular	O
convention	O
is	O
to	O
use	O
filename	O
extensions	O
;	O
for	O
instance	O
,	O
if	O
CGI	B-Language
scripts	I-Language
are	O
consistently	O
given	O
the	O
extension	O
.cgi	B-Language
,	O
the	O
Web	B-Application
server	I-Application
can	O
be	O
configured	O
to	O
interpret	O
all	O
such	O
files	O
as	O
CGI	B-Language
scripts	I-Language
.	O
</s>
<s>
In	O
the	O
case	O
of	O
HTTP	B-Protocol
PUT	O
or	O
POSTs	O
,	O
the	O
user-submitted	O
data	O
are	O
provided	O
to	O
the	O
program	O
via	O
the	O
standard	O
input	O
.	O
</s>
<s>
The	O
Web	B-Application
server	I-Application
creates	O
a	O
subset	O
of	O
the	O
environment	O
variables	O
passed	O
to	O
it	O
and	O
adds	O
details	O
pertinent	O
to	O
the	O
HTTP	B-Protocol
environment	O
.	O
</s>
<s>
CGI	O
is	O
often	O
used	O
to	O
process	B-Operating_System
input	O
information	O
from	O
the	O
user	O
and	O
produce	O
the	O
appropriate	O
output	O
.	O
</s>
<s>
An	O
example	O
of	O
a	O
CGI	O
program	O
is	O
one	O
implementing	O
a	O
wiki	B-Protocol
.	O
</s>
<s>
If	O
the	O
user	O
agent	O
requests	O
the	O
name	O
of	O
an	O
entry	O
,	O
the	O
Web	B-Application
server	I-Application
executes	O
the	O
CGI	O
program	O
.	O
</s>
<s>
The	O
CGI	O
program	O
retrieves	O
the	O
source	O
of	O
that	O
entry	O
's	O
page	O
(	O
if	O
one	O
exists	O
)	O
,	O
transforms	O
it	O
into	O
HTML	B-Language
,	O
and	O
prints	O
the	O
result	O
.	O
</s>
<s>
The	O
Web	B-Application
server	I-Application
receives	O
the	O
output	O
from	O
the	O
CGI	O
program	O
and	O
transmits	O
it	O
to	O
the	O
user	O
agent	O
.	O
</s>
<s>
Then	O
if	O
the	O
user	O
agent	O
clicks	O
the	O
"	O
Edit	O
page	O
"	O
button	O
,	O
the	O
CGI	O
program	O
populates	O
an	O
HTML	B-Language
textarea	O
or	O
other	O
editing	O
control	O
with	O
the	O
page	O
's	O
contents	O
.	O
</s>
<s>
Finally	O
if	O
the	O
user	O
agent	O
clicks	O
the	O
"	O
Publish	O
page	O
"	O
button	O
,	O
the	O
CGI	O
program	O
transforms	O
the	O
updated	O
HTML	B-Language
into	O
the	O
source	O
of	O
that	O
entry	O
's	O
page	O
and	O
saves	O
it	O
.	O
</s>
<s>
CGI	O
programs	O
run	O
,	O
by	O
default	O
,	O
in	O
the	O
security	O
context	O
of	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
When	O
first	O
introduced	O
a	O
number	O
of	O
example	O
scripts	O
were	O
provided	O
with	O
the	O
reference	O
distributions	O
of	O
the	O
NCSA	O
,	O
Apache	B-Application
and	O
CERN	O
Web	B-Application
servers	I-Application
to	O
show	O
how	O
shell	O
scripts	O
or	O
C	B-Language
programs	I-Language
could	O
be	O
coded	O
to	O
make	O
use	O
of	O
the	O
new	O
CGI	O
.	O
</s>
<s>
The	O
function	O
was	O
supposed	O
to	O
sanitize	O
its	O
argument	O
,	O
which	O
came	O
from	O
user	O
input	O
and	O
then	O
pass	O
the	O
input	O
to	O
the	O
Unix	B-Application
shell	O
,	O
to	O
be	O
run	O
in	O
the	O
security	O
context	O
of	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
The	O
results	O
of	O
these	O
commands	O
were	O
then	O
displayed	O
on	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
If	O
the	O
security	O
context	O
of	O
the	O
Web	B-Application
server	I-Application
allowed	O
it	O
,	O
malicious	O
commands	O
could	O
be	O
executed	O
by	O
attackers	O
.	O
</s>
<s>
This	O
was	O
the	O
first	O
widespread	O
example	O
of	O
a	O
new	O
type	O
of	O
Web	O
based	O
attack	O
,	O
where	O
unsanitized	O
data	O
from	O
Web	O
users	O
could	O
lead	O
to	O
execution	O
of	O
code	O
on	O
a	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
For	O
each	O
incoming	O
HTTP	B-Protocol
request	O
,	O
a	O
Web	B-Application
server	I-Application
creates	O
a	O
new	O
CGI	O
process	B-Operating_System
for	O
handling	O
it	O
and	O
destroys	O
the	O
CGI	O
process	B-Operating_System
after	O
the	O
HTTP	B-Protocol
request	O
has	O
been	O
handled	O
.	O
</s>
<s>
Creating	O
and	O
destroying	O
a	O
process	B-Operating_System
can	O
consume	O
much	O
more	O
CPU	O
and	O
memory	O
than	O
the	O
actual	O
work	O
of	O
generating	O
the	O
output	O
of	O
the	O
process	B-Operating_System
,	O
especially	O
when	O
the	O
CGI	O
program	O
still	O
needs	O
to	O
be	O
interpreted	O
by	O
a	O
virtual	O
machine	O
.	O
</s>
<s>
For	O
a	O
high	O
number	O
of	O
HTTP	B-Protocol
requests	I-Protocol
,	O
the	O
resulting	O
workload	O
can	O
quickly	O
overwhelm	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
The	O
overhead	O
involved	O
in	O
CGI	O
process	B-Operating_System
creation	O
and	O
destruction	O
can	O
be	O
reduced	O
by	O
the	O
following	O
techniques	O
:	O
</s>
<s>
CGI	O
programs	O
precompiled	O
to	O
machine	B-Language
code	I-Language
,	O
e.g.	O
</s>
<s>
precompiled	O
from	O
C	B-Language
or	O
C++	B-Language
programs	I-Language
,	O
rather	O
than	O
CGI	O
programs	O
interpreted	O
by	O
a	O
virtual	O
machine	O
,	O
e.g.	O
</s>
<s>
Perl	B-Language
,	O
PHP	B-Application
or	O
Python	B-Language
programs	I-Language
.	O
</s>
<s>
Web	B-Application
server	I-Application
extensions	O
such	O
as	O
Apache	B-Application
modules	I-Application
(	O
e.g.	O
</s>
<s>
mod_perl	O
,	O
mod_php	O
,	O
mod_python	O
)	O
,	O
NSAPI	B-Application
plugins	O
,	O
and	O
ISAPI	B-Library
plugins	O
which	O
allow	O
long-running	O
application	O
processes	O
handling	O
more	O
than	O
one	O
request	O
and	O
hosted	O
within	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
Web	O
2.0	O
allows	O
to	O
transfer	O
data	O
from	O
the	O
client	O
to	O
the	O
server	O
without	O
using	O
HTML	B-General_Concept
forms	I-General_Concept
and	O
without	O
the	O
user	O
noticing	O
.	O
</s>
<s>
FastCGI	O
,	O
SCGI	B-Protocol
,	O
and	O
AJP	B-Application
which	O
allow	O
long-running	O
application	O
processes	O
handling	O
more	O
than	O
one	O
request	O
to	O
be	O
hosted	O
externally	O
;	O
i.e.	O
,	O
separately	O
from	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
Each	O
application	O
process	B-Operating_System
listens	O
on	O
a	O
socket	O
;	O
the	O
Web	B-Application
server	I-Application
handles	O
an	O
HTTP	B-Protocol
request	O
and	O
sends	O
it	O
via	O
another	O
protocol	O
(	O
FastCGI	O
,	O
SCGI	B-Protocol
or	O
AJP	B-Application
)	O
to	O
the	O
socket	O
only	O
for	O
dynamic	O
content	O
,	O
while	O
static	O
content	O
is	O
usually	O
handled	O
directly	O
by	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
This	O
approach	O
needs	O
fewer	O
application	O
processes	O
so	O
consumes	O
less	O
memory	O
than	O
the	O
Web	B-Application
server	I-Application
extension	O
approach	O
.	O
</s>
<s>
And	O
unlike	O
converting	O
an	O
application	O
program	O
to	O
a	O
Web	B-Application
server	I-Application
extension	O
,	O
FastCGI	O
,	O
SCGI	B-Protocol
,	O
and	O
AJP	B-Application
application	O
programs	O
remain	O
independent	O
of	O
the	O
Web	B-Application
server	I-Application
.	O
</s>
<s>
Jakarta	B-Language
EE	I-Language
runs	O
Jakarta	B-Application
Servlet	I-Application
applications	O
in	O
a	O
Web	B-Language
container	I-Language
to	O
serve	O
dynamic	O
content	O
and	O
optionally	O
static	O
content	O
which	O
replaces	O
the	O
overhead	O
of	O
creating	O
and	O
destroying	O
processes	O
with	O
the	O
much	O
lower	O
overhead	O
of	O
creating	O
and	O
destroying	O
threads	B-Operating_System
.	O
</s>
<s>
It	O
also	O
exposes	O
the	O
programmer	O
to	O
the	O
library	O
that	O
comes	O
with	O
Java	B-Language
SE	I-Language
on	O
which	O
the	O
version	O
of	O
Jakarta	B-Language
EE	I-Language
in	O
use	O
is	O
based	O
.	O
</s>
<s>
Web	B-Application
frameworks	I-Application
offer	O
an	O
alternative	O
to	O
using	O
CGI	B-Language
scripts	I-Language
to	O
interact	O
with	O
user	O
agents	O
.	O
</s>
