Document written by Michael Neumann (neumann@s-direktnet.de).
require "fcgi"
FGCI.each_request do |req|
puts "Content-type: text/html\n"
puts "<html><body><ul>"
ENV.each {|k,v| puts "<li><b>#{k}: </b> #{v}</li>" }
puts "</ul></body></html>"
end
Used in conjunction with class CGI:
require "fcgi"
require "cgi"
FCGI.each_request do |req|
$stdin = req.in # to handle POST requests
cgi = CGI.new
puts "Content-type: text/html\n"
puts "<html><body>"
puts cgi.params.inspect
puts "</body></html>"
# remove CGI::CGI_PARAMS and CGI::CGI_COOKIES, so that
# class CGI will reread the parameters.
class CGI
remove_const :CGI_PARAMS
remove_const :CGI_COOKIES
end
end
The class for handling FastCGI requests.
Unlike CGI-scripts, FastCGI-programs are (normally) executed only once and are hold in memory. So the overhead of process creation is eleminated which results in (often great) speed improvements.
Due to the fact that FastCGI applications do not (normally) exit, all variables declared in a FastCGI application are accessible for each request. There is no need (like in CGIs) to store variables which should be persistent between requests to disk. Also, database connections can be shared, i.e. they must only be connected once.
All CGI environment variables are also existent in FastCGI, plus some more.
Please see <URL:http://www.fastcgi.com/> for more informations.
FCGI.accept
Waits for a new FastCGI request.
When successful, the methods returns an object of
type FCGI, and sets $stdout automatically
to FCGI#out of the returned object.
If an error occured, the method retuns nil.
The environment variables (ENV)are also changed!
FCGI.newSynonym for FCGI.accept.
FCGI.each_request {|req| block }
Calls the block block for each FastCGI request.
req is an object of type FCGI and represents the
actual request.
Sets automatically $stdout to the value of FCGI#out
of the object represented by req.
The environment variables (ENV)are also changed!
FCGI.each {|req| block }Synonym for FCGI.each_request.
FCGI#inReturns an object of type FCGI::Stream which represents the standard input.
FCGI#outReturns an object of type FCGI::Stream which represents the standard output.
FCGI#errReturns an object of type FCGI::Stream which represents the standard error.
FCGI::Stream#putc( char )
Writes char, which must be of type Numerical into the
stream. Returns the written character.
FCGI::Stream#write( str )Writes the string str into the stream and returns the length of the written string.
FCGI::Stream#print
Works like Kernel#print.
FCGI::Stream#printf
Works like Kernel#printf.
FCGI::Stream#puts
Works like Kernel#puts.
FCGI::Stream#<<( str )Synonym for FCGI::Stream#write.
FCGI::Stream#flushFlushes the stream.
FCGI::Stream#getc
Returns the next character from the stream.
Returns nil on EOF.
FCGI::Stream#ungetc( char )Puts char back to the stream.
FCGI::Stream#gets
Works like Kernel#gets.
FCGI::Stream#read ( num )
Reads num bytes from the stream and returns a string,
if more than zero bytes were read, otherwise returns nil.
FCGI::Stream#eof
Returns true on EOF, otherwise false.
FCGI::Stream#eof?Synonym for FCGI::Stream#eof.
FCGI::Stream#closeCloses the stream.
FCGI::Stream#closed?
Returns true if the stream was already closed, otherwise false.
StandardError
Unknown error.
Unsupported version.
Protocol error.
Parameter error.
Preconditions are not met.
$Id: fcgi.rd,v 1.3 2001/02/12 16:51:35 michael Exp $