# FCGI: How do you use it?

**URL:** <https://rubytalk.org/t/fcgi-how-do-you-use-it/29268>\
**Category:** ruby-talk\
**Created:** [25 July 2006 10:29 UTC](https://rubytalk.org/t/fcgi-how-do-you-use-it/29268 "2006-07-25T10:29:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Allison](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@Tom\_Allison](https://rubytalk.org/u/Tom_Allison)\
**Post date:** [25 July 2006 10:29 UTC](https://rubytalk.org/t/fcgi-how-do-you-use-it/29268/1 "2006-07-25T10:29:27Z")

</div>

I'm kind of perplexed here so I'll ask the stupid questions.

When I use perl and call for a CGI module, I get with it all kinds of really  
cool abilities related to %ENV and STDIN/STDOUT and the ability to even set  
cookies...

I can't find much of anything about what FCGI/FastCGI offers in terms of methods  
or properties that are similar..

Is it correct to assume that FCGI doesn't do any of this and if I'm interested  
in any kind of CGI related functionality (headers, cookies, %ENV...) then I  
should probably just load the CGI modules?

Now onto the Ruby specific nature of the question, but if anyone here knows the perl-specific question above I would also appreciate it:

Is there some way I can run the ruby fcgi scripts from command line to test? Editing and restarting apache all the time is not very fun.

Under ruby should I load fcgi, cgi, cgi/cookie, cgi/session rather  
than expecting any of this kind of insight into the HTTP process from the FCGI  
working environment? (please don't take any of these negative questions to be a  
slight on FCGI/FastCGI

It's a stupid question but I would feel stupider if I found I was loading  
multiple modules when only one was required. I haven't really found anything  
that tells me that fcgi does other than some rudimentary examples. (or is it  
that simple and I'm just trying to make it complicated?)

Simply put, I can't seem to find any way to discover what fcgi provides under ruby (variables, methods). But I would like to use it and understand that many do.

The documentation around the whole FastCGI thing is either very slim or hard to find. I did not find the whitepaper a very encouraging read since I'm not designing an HTTP server. I'm trying to be a user of the product.

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [25 July 2006 14:33 UTC](https://rubytalk.org/t/fcgi-how-do-you-use-it/29268/2 "2006-07-25T14:33:05Z")

</div>

> I'm kind of perplexed here so I'll ask the stupid questions.
> 
> When I use perl and call for a CGI module, I get with it all kinds of really  
> cool abilities related to %ENV and STDIN/STDOUT and the ability to even set  
> cookies...
> 
> I can't find much of anything about what FCGI/FastCGI offers in terms of  
> methods or properties that are similar..
> 
> Is it correct to assume that FCGI doesn't do any of this and if I'm  
> interested in any kind of CGI related functionality (headers, cookies,  
> %ENV...) then I should probably just load the CGI modules?

fcgi loads the cgi module for you. when you write

&nbsp;&nbsp;&nbsp;FCGI.each\_cgi do |cgi|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^  
&nbsp;&nbsp;&nbsp;end

then cgi is a cgi object with all the methods any cgi object has (mostly).  
these are documented in standard ruby docs, which can be found most anywhere,  
including [http://rubydoc.org](http://rubydoc.org).

> Now onto the Ruby specific nature of the question, but if anyone here knows  
> the perl-specific question above I would also appreciate it:
> 
> Is there some way I can run the ruby fcgi scripts from command line to test?  
> Editing and restarting apache all the time is not very fun.

i answered this in your other post, but here it goes again:

here is an example fcgi program:

&nbsp;&nbsp;&nbsp;fortytwo :/var/www/html \> cat env2.fcgi  
&nbsp;&nbsp;&nbsp;#! /usr/local/bin/ruby  
&nbsp;&nbsp;&nbsp;require 'rubygems' rescue nil  
&nbsp;&nbsp;&nbsp;require 'fcgi'  
&nbsp;&nbsp;&nbsp;require 'yaml'

&nbsp;&nbsp;&nbsp;FCGI.each\_cgi{|cgi| cgi.out{ "\<pre\>#{ cgi.env\_table.to\_hash.to\_yaml }\</pre\>" }}

and here's running it

&nbsp;&nbsp;&nbsp;fortytwo :/var/www/html \> ./env2.fcgi \</dev/null | head  
&nbsp;&nbsp;&nbsp;Content-Type: text/html  
&nbsp;&nbsp;&nbsp;Content-Length: 4037

&nbsp;&nbsp;&nbsp;\<pre\>---  
&nbsp;&nbsp;&nbsp;XAUTHORITY: /home/ahoward/.Xauthority  
&nbsp;&nbsp;&nbsp;GS\_LIB: /home/ahoward/.fonts  
&nbsp;&nbsp;&nbsp;SSH\_ASKPASS: /usr/libexec/openssh/gnome-ssh-askpass  
&nbsp;&nbsp;&nbsp;KONSOLE\_DCOP\_SESSION: DCOPRef(konsole-4421,session-4)  
&nbsp;&nbsp;&nbsp;MAIL: /var/spool/mail/ahoward  
&nbsp;&nbsp;&nbsp;KDEDIR: /usr

> Under ruby should I load fcgi, cgi, cgi/cookie, cgi/session rather than  
> expecting any of this kind of insight into the HTTP process from the FCGI  
> working environment? (please don't take any of these negative questions to  
> be a slight on FCGI/FastCGI

you don't need to load cgi. you must load cgi/cookie and cgi/session if you  
intende you use them. they are also documented in the standard docs.

> It's a stupid question but I would feel stupider if I found I was loading  
> multiple modules when only one was required. I haven't really found  
> anything that tells me that fcgi does other than some rudimentary examples.  
> (or is it that simple and I'm just trying to make it complicated?)

i think that may be the case 😉 the source is also quite simple if you take a  
look at it. fcgi ships with a pure ruby version which is light reading.

> Simply put, I can't seem to find any way to discover what fcgi provides  
> under ruby (variables, methods). But I would like to use it and understand  
> that many do.
> 
> The documentation around the whole FastCGI thing is either very slim or hard  
> to find. I did not find the whitepaper a very encouraging read since I'm  
> not designing an HTTP server. I'm trying to be a user of the product.

the key is that fcgi hands you a cgi-like object and that object \_\_is\_\_ documented.

good luck.

-a

> **···**
>
> On Tue, 25 Jul 2006, Tom Allison wrote:  
> --  
> suffering increases your inner strength. also, the wishing for suffering  
> makes the suffering disappear.  
> - h.h. the 14th dali lama

---

<div class="post-metadata">

**Author:** ![Tom\_Allison](https://avatars.discourse-cdn.com/v4/letter/t/258eb7/32.png) [@Tom\_Allison](https://rubytalk.org/u/Tom_Allison)\
**Post date:** [25 July 2006 17:44 UTC](https://rubytalk.org/t/fcgi-how-do-you-use-it/29268/3 "2006-07-25T17:44:18Z")

</div>

> the key is that fcgi hands you a cgi-like object and that object \_\_is\_\_ documented.

this is "key". I now have some direction in which to go play. Thank  
you.

Should I assume that

fcgi.each do |request|

returns something akin to perls http::request object (useble but  
clunkier) and

fcgi.each\_cgi do |cgi|

returns a CGI object with is easier to code with.

Since it loads CGI anyways, there really isn't any memory savings on  
either of these approaches, but little things can be handled with  
'requests' probably faster than if they are treated as cgi objects.

Thank you.

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [25 July 2006 17:46 UTC](https://rubytalk.org/t/fcgi-how-do-you-use-it/29268/4 "2006-07-25T17:46:41Z")

</div>

> > the key is that fcgi hands you a cgi-like object and that object \_\_is\_\_ documented.
> 
> this is "key". I now have some direction in which to go play. Thank  
> you.
> 
> Should I assume that
> 
> fcgi.each do |request|
> 
> returns something akin to perls http::request object (useble but  
> clunkier) and
> 
> fcgi.each\_cgi do |cgi|
> 
> returns a CGI object with is easier to code with.

exactly.

> Since it loads CGI anyways, there really isn't any memory savings on  
> either of these approaches, but little things can be handled with  
> 'requests' probably faster than if they are treated as cgi objects.

maybe - though i doubt a real application would be bottlenecked here.

regards.

-a

> **···**
>
> On Wed, 26 Jul 2006, Tom Allison wrote:  
> --  
> suffering increases your inner strength. also, the wishing for suffering  
> makes the suffering disappear.  
> - h.h. the 14th dali lama
