Skip to content
The next generation of Ruby FCGI gem with support of ruby18, ruby18ee, ruby19, jruby, rbx. Will be ported to ruby20.
Ruby C
Branch: master
Clone or download
msva Merge pull request #6 from vipulnsward/fix-warnings
Fix some long running ruby warnings.
Latest commit 58cd6b3 Feb 21, 2014
Type Name Latest commit message Commit time
Failed to load latest commit information.
ext/fcgi Migrate from select to rb_thread_fd_select Jan 27, 2014
test Initial commit Jan 17, 2013
LICENSE Initial commit Jan 17, 2013
README.rdoc New minor release Sep 30, 2013
VERSION New minor release Sep 30, 2013
fcgi.gemspec New minor release Sep 30, 2013


fcgi - The New generation of FastCGI library for Ruby.



C version

* ((<libfcgi|URL:>))(FastCGI Developer's Kit)

Pure Ruby Version

* StringIO


$ gem install fcgi


Class Method

— FCGI.accept

Returns FCGI instance

— FCGI.each

— FCGI.each_request

— FCGI.is_cgi?

— FCGI.each_cgi

Automatically detects whether this program is running under the FastCGI
environment, and generates a 'CGI' type object for each request. Also
installs signal handlers for graceful handling of SIGPIPE (which may
occur if a client gives up on a request before it is complete) and
SIGUSR1 (generated by Apache for a 'graceful' exit)

If you are using the HTML output methods you can also pass the HTML type
e.g. FCGI.each_cgi('html3') do ... end

However, you should beware that the CGI library is quite slow when
used in this way, as it dynamically adds a large number of methods
to itself each time a new instance is created.

Instance Method

— FCGI#finish


— FCGI#in

Returns Stream or StringIO

— FCGI#out

Returns Stream or StringIO

— FCGI#err

Returns Stream or StringIO

— FCGI#env

Returns Environment(Hash)


Using the FastCGI native interface:

require "fcgi"

FCGI.each {|request|
  out = request.out
  out.print "Content-Type: text/plain\r\n"
  out.print "\r\n"

Using the CGI-compatible interface, which works both as a standalone CGI and under FastCGI with no modifications:

require "fcgi"

FCGI.each_cgi {|cgi|
  name = cgi['name'][0]
  puts cgi.header
  puts "You are #{name} " if name
  puts "Connecting from #{cgi.remote_addr}"

Note: you can't reference CGI environment variables using ENV when under FastCGI. It is recommended that you use the CGI-generated methods, e.g. cgi.remote_addr as above.

If you need to access environment variables directly, perhaps extra ones set in your Apache config, then use cgi.env_table instead. This isn't quite as portable because env_table is a private method in the standard CGI library.



fcgi.c     0.1   Copyright (C) 1998-1999  Network Applied Communication Laboratory, Inc.
           0.8   Copyright (C) 2002 MoonWolf <>
           0.9   Copyright (C) 2013 mva <> Alpha, LLC

fastcgi.rb 0.7   Copyright (C) 2001 Eli Green
fcgi.rb    0.8   Copyright (C) 2002 MoonWolf <>
fcgi.rb    0.8.5 Copyright (C) 2004 Minero Aoki
You can’t perform that action at this time.