<s>
The	O
Simple	B-Protocol
Common	I-Protocol
Gateway	I-Protocol
Interface	I-Protocol
(	O
SCGI	B-Protocol
)	O
is	O
a	O
protocol	O
for	O
applications	O
to	O
interface	O
with	O
HTTP	B-Protocol
servers	O
,	O
as	O
an	O
alternative	O
to	O
the	O
CGI	B-Language
protocol	O
.	O
</s>
<s>
Unlike	O
CGI	B-Language
,	O
it	O
permits	O
a	O
long-running	O
service	O
process	O
to	O
continue	O
serving	O
requests	O
,	O
thus	O
avoiding	O
delays	O
in	O
responding	O
to	O
requests	O
due	O
to	O
setup	O
overhead	O
(	O
such	O
as	O
connecting	O
to	O
a	O
database	O
)	O
.	O
</s>
<s>
SCGI	B-Protocol
is	O
a	O
protocol	O
which	O
defines	O
communication	O
between	O
a	O
web	O
server	O
and	O
an	O
application	O
server	O
.	O
</s>
<s>
This	O
is	O
in	O
contrast	O
to	O
CGI	B-Language
,	O
which	O
is	O
an	O
earlier	O
application	O
(	O
gateway	O
)	O
interface	O
designed	O
to	O
let	O
the	O
application	O
programmer	O
avoid	O
the	O
complexity	O
of	O
sockets	O
and	O
long-running	O
service	O
processes	O
when	O
poor	O
scalability	O
and	O
high	O
overhead	O
are	O
acceptable	O
.	O
</s>
<s>
The	O
SCGI	B-Protocol
protocol	O
leverages	O
the	O
fact	O
that	O
the	O
web	O
server	O
has	O
already	O
parsed	O
and	O
validated	O
the	O
HTTP	B-Protocol
request	O
,	O
and	O
canonically	O
communicates	O
the	O
request	O
to	O
the	O
SCGI	B-Protocol
server	O
while	O
letting	O
the	O
application	O
programmer	O
avoid	O
parsing	O
ambiguities	O
and	O
protocol	O
edge	O
cases	O
.	O
</s>
<s>
This	O
avoids	O
the	O
complicated	O
header-parsing	O
and	O
header-combining	O
rules	O
from	O
RFC	B-Protocol
2616	I-Protocol
,	O
saving	O
significant	O
complexity	O
in	O
the	O
SCGI	B-Protocol
server	O
process	O
.	O
</s>
<s>
Neil	O
Schemenauer	O
published	O
the	O
original	O
SCGI	B-Protocol
protocol	O
specification	O
dated	O
October	O
2001	O
.	O
</s>
<s>
He	O
developed	O
the	O
first	O
implementations	O
of	O
SCGI	B-Protocol
and	O
initially	O
published	O
them	O
in	O
April	O
2002	O
.	O
</s>
<s>
The	O
client	O
connects	O
to	O
a	O
SCGI	B-Protocol
server	O
over	O
a	O
reliable	O
stream	O
protocol	O
allowing	O
transmission	O
of	O
8-bit	O
bytes	O
.	O
</s>
<s>
When	O
the	O
SCGI	B-Protocol
server	O
sees	O
the	O
end	O
of	O
the	O
request	O
it	O
sends	O
back	O
a	O
response	O
and	O
closes	O
the	O
connection	O
.	O
</s>
<s>
The	O
format	O
of	O
the	O
response	O
is	O
not	O
specifically	O
specified	O
by	O
this	O
protocol	O
,	O
although	O
CGI-equivalent	O
HTTP	B-Protocol
responses	O
are	O
generally	O
used	O
.	O
</s>
<s>
A	O
SCGI	B-Protocol
request	O
is	O
the	O
concatenation	O
of	O
netstring-encoded	O
headers	O
and	O
a	O
body	O
.	O
</s>
<s>
A	O
SCGI	B-Protocol
response	O
is	O
a	O
normal	O
HTTP	B-Protocol
response	O
.	O
</s>
<s>
Each	O
header	O
consists	O
of	O
a	O
name	B-Application
–	I-Application
value	I-Application
pair	I-Application
,	O
where	O
both	O
the	O
name	O
and	O
the	O
value	O
are	O
null-terminated	B-Data_Structure
strings	I-Data_Structure
(	O
C	B-Language
strings	I-Language
)	O
.	O
</s>
<s>
These	O
considerations	O
are	O
standard	O
for	O
C	B-Language
strings	I-Language
,	O
but	O
are	O
often	O
confusing	O
for	O
programmers	O
used	O
to	O
other	O
standards	O
for	O
string-handling	O
.	O
</s>
<s>
All	O
provided	O
headers	O
are	O
concatenated	O
to	O
form	O
a	O
single	O
byte	O
sequence	O
,	O
then	O
netstring-encoded	O
.	O
</s>
<s>
There	O
must	O
also	O
always	O
be	O
a	O
request	O
header	O
with	O
the	O
name	O
"	O
SCGI	B-Protocol
"	O
and	O
a	O
value	O
of	O
"	O
1	O
"	O
.	O
</s>
<s>
Standard	O
CGI	B-Language
environment	O
variables	O
should	O
be	O
provided	O
in	O
SCGI	B-Protocol
headers	O
for	O
compatibility	O
when	O
converting	O
older	O
CGI	B-Language
programs	O
to	O
SCGI	B-Protocol
.	O
</s>
<s>
While	O
the	O
SCGI	B-Protocol
protocol	O
insulates	O
the	O
service	O
programmer	O
from	O
some	O
HTTP	B-Protocol
considerations	O
,	O
various	O
details	O
(	O
such	O
as	O
interpreting	O
the	O
octets	O
of	O
the	O
message	O
body	O
as	O
per	O
the	O
Transfer-Encoding	O
header	O
,	O
the	O
CONTENT_LENGTH	O
being	O
the	O
number	O
of	O
octets	O
after	O
the	O
body	O
has	O
been	O
encoded	O
for	O
transmission	O
,	O
etc	O
.	O
)	O
</s>
<s>
still	O
require	O
knowledge	O
of	O
the	O
HTTP	B-Protocol
protocol	I-Protocol
specification	O
.	O
</s>
<s>
The	O
web	O
server	O
(	O
a	O
SCGI	B-Protocol
client	O
)	O
opens	O
a	O
connection	O
and	O
sends	O
the	O
concatenation	O
of	O
the	O
following	O
strings	O
to	O
the	O
service	O
process	O
(	O
a	O
SCGI	B-Protocol
server	O
)	O
:	O
</s>
<s>
The	O
SCGI	B-Protocol
server	O
sends	O
the	O
following	O
response	O
back	O
to	O
the	O
web	O
server	O
:	O
</s>
<s>
The	O
SCGI	B-Protocol
server	O
closes	O
the	O
connection	O
.	O
</s>
<s>
SCGI	B-Protocol
can	O
be	O
implemented	O
in	O
any	O
language	O
that	O
supports	O
network	B-Protocol
sockets	I-Protocol
and	O
netstrings	B-Protocol
.	O
</s>
<s>
The	O
following	O
is	O
a	O
partial	O
list	O
of	O
languages	O
with	O
known	O
SCGI	B-Protocol
bindings	O
:	O
</s>
