Fastcgi + eruby

What is the best way to handle .rhtml (eruby) documents using fastcgi?

I'm using Linux, Apache2 and fcgi 0.8.4.

I'm trying to convert a site from mod_ruby to fastcgi so I can run some comparison tests.

Converting .rbx was easy but I'm not sure how to best handle .rhtml.

Maybe use the erb interpreter, and use fcgi instead of cgi? I think that might work, but at the expense of having to insert a big loop into all your rhtml templates. There's a cool continuation hack that matz wrote to make cgi work with fcgi, without any code changes. But there are some ruby bugs that affect continuations.

~ patrick

···

On Monday, November 1, 2004, at 09:33 AM, J. D. wrote:

What is the best way to handle .rhtml (eruby) documents using fastcgi?

I'm using Linux, Apache2 and fcgi 0.8.4.

I'm trying to convert a site from mod_ruby to fastcgi so I can run some comparison tests.

Converting .rbx was easy but I'm not sure how to best handle .rhtml.

What is the best way to handle .rhtml (eruby) documents using fastcgi?

I'm using Linux, Apache2 and fcgi 0.8.4.

I'm trying to convert a site from mod_ruby to fastcgi so I can run some
comparison tests.

Converting .rbx was easy but I'm not sure how to best handle .rhtml.

Tricky, because it's a different way of working.

If you change each .rhtml page into a separate fcgi script, then you will
have a separate persistent process for every page, which you probably don't
want if there are hundreds of pages.

You can write a simple fcgi program which reads a filename from the URL,
fetches and compiles the appropriate page (or gets it from a cache) and runs
it: e.g.

http://www.example.com/fcgi-bin/view/foo.rhtml

But then your URLs change. You could use mod_rewrite to chomp your URLs into
the appropriate new format though. Or you might be able to use "Action
handler-name" in the appropriate Directory / Location section.

I wouldn't just do it for the fun of it, or for making speed comparisons
(almost certainly the speed will be the same or slightly slower than
mod_ruby, since you're still doing the eruby work in Ruby, and you have the
extra overhead of communicating with a separate worker process rather than
the Apache httpd process running the Ruby itself)

I'd suggest you only do it if you're moving to an environment where
mod_fastcgi is available but mod_ruby isn't.

Cheers,

Brian.

fastcgi works as a cgi out of the box without any code changes or
continuations? are you referring to something else, or the method used by
fcgi?

kind regards.

-a

···

On Mon, 1 Nov 2004, Patrick May wrote:

On Monday, November 1, 2004, at 09:33 AM, J. D. wrote:

What is the best way to handle .rhtml (eruby) documents using fastcgi?

I'm using Linux, Apache2 and fcgi 0.8.4.

I'm trying to convert a site from mod_ruby to fastcgi so I can run
some comparison tests.

Converting .rbx was easy but I'm not sure how to best handle .rhtml.

Maybe use the erb interpreter, and use fcgi instead of cgi? I think
that might work, but at the expense of having to insert a big loop into
all your rhtml templates. There's a cool continuation hack that matz
wrote to make cgi work with fcgi, without any code changes. But there
are some ruby bugs that affect continuations.

~ patrick

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
When you do something, you should burn yourself completely, like a good
bonfire, leaving no trace of yourself. --Shunryu Suzuki

===============================================================================

Patrick May wrote:

What is the best way to handle .rhtml (eruby) documents using fastcgi?

I'm using Linux, Apache2 and fcgi 0.8.4.

I'm trying to convert a site from mod_ruby to fastcgi so I can run some comparison tests.

Converting .rbx was easy but I'm not sure how to best handle .rhtml.

Maybe use the erb interpreter, and use fcgi instead of cgi? I think that might work, but at the expense of having to insert a big loop into all your rhtml templates. There's a cool continuation hack that matz wrote to make cgi work with fcgi, without any code changes. But there are some ruby bugs that affect continuations.

~ patrick

Thanks, you're right about erb!

Googling 'erb' instead of 'eruby' resulted in finding this:

http://pub.cozmixng.org/~the-rwiki/rw-cgi.rb?cmd=view;name=ERbMemo.en

The part about 'using as a library' on the page was particularly helpful. I guess I can just include it inside the fcgi loop.

···

On Monday, November 1, 2004, at 09:33 AM, J. D. wrote:

Is this still true? I did some tests with the newest ruby-stable, and it
seems that these problems are gone. Can anybody confirm?

Regards,

  Michael

···

On Mon, Nov 01, 2004 at 11:46:01PM +0900, Patrick May wrote:

On Monday, November 1, 2004, at 09:33 AM, J. D. wrote:

>What is the best way to handle .rhtml (eruby) documents using fastcgi?
>
>I'm using Linux, Apache2 and fcgi 0.8.4.
>
>I'm trying to convert a site from mod_ruby to fastcgi so I can run
>some comparison tests.
>
>Converting .rbx was easy but I'm not sure how to best handle .rhtml.

Maybe use the erb interpreter, and use fcgi instead of cgi? I think
that might work, but at the expense of having to insert a big loop into
all your rhtml templates. There's a cool continuation hack that matz
wrote to make cgi work with fcgi, without any code changes. But there
are some ruby bugs that affect continuations.

Hi,

fastcgi works as a cgi out of the box without any code changes or
continuations? are you referring to something else, or the method used by
fcgi?

The best case for continuations I have seen is demonstrated by Matz in [ruby-talk:13428]

   http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/13428

It's quite a cool trick -- no each_request loop. I did experience a few bugs in the combination of callcc and at_exit on darwin. I hope they are fixed in the latest stable branch, because I think this is the coolest.

Cheers,

Patrick

···

On Monday, November 1, 2004, at 10:13 AM, Ara.T.Howard@noaa.gov wrote: