From: Walton Hoops Date: 2009-11-26T04:49:59+09:00 Subject: Re: Ruby a good choice for CGI? > -----Original Message----- > From: nickhannum@gmail.com [mailto:nickhannum@gmail.com] > > Ive been messing around with Ruby for a few weeks now, and I'm fairly > comfortable with the language itself, but now I want to host a *very* > tiny app on the net, and I'm getting very overwhelmed with the massive > array of frameworks and technologies available. > > I'll describe what I'm trying to, and maybe someone here can just point > me in the right direction and spare me weeks of wading through doc to > find out all about each of these things. > > I've written a small HTML/JQuery page that displays a simple UI on a > canvas element. The user clicks on pictures of buttons and the JQuery > posts a string to the server. I need some server side code - hopefully > ruby b/c i like the syntax, and i've heard bad things about PHP - that > will take the command from the POST, hit a MySQL db, and return a > string > response. The JQuery takes the string response and updates the canvas. > > Really simple right? I already have the HTML/JQuery/Canvas-draw. I've > already got the Ruby code itself, including the MySQL part. > > I went to host it, and figured I'd try it at home before I spent any > money. I installed Apache on my Ubuntu box, dropped the Ruby files into > the cgi-bin folder, used the ruby cgi lib in my script and it all > worked. Then the plane crashed in the mountain. > > I started reading online and people said pure CGI was way too slow b/c > I'll be loading and disposing of all my code and db connections each > request. That sounds bad. So what do I do? I've be told things about > FastCGI, Passenger, mod_ruby, Rack, Sinatra, Camping, etc. and I can't > even figure out which one I need! > > Can someone point me in the right direction here? My app is VERY small. > Practically no code, no HTML output. All I need is to execute the 2 or > 3 > Ruby functions I already have, on the net, with some basic > cookie/session support. What's the least headache(and not terribly > slow) > way to do this? DISCLAIMER: I don't actually use Ruby for webapps CGI is ok, if and only if your web traffic is very low. If you Expect a lot of traffic, or your traffic will be coming in bursts, you definitely want to figure something else out. For something as simple as you seem to be describing, I would recommend either mod_ruby, or fastcgi. Mod_ruby is akin to mod_php5 or mod_python where the Ruby interpreter is actually imbedded in the Apache server. FastCGI on the other hand is similar to CGI, except that the process is reused for requests rather than starting a new one for each request. I'm not sure which will be easier, but either should be able to handle what you need, and I think both should be fairly simple setups. Both are available in Ubuntu via: sudo apt-get install libapache2-mod-fastcgi sudo apt-get install libapache2-mod-ruby I hope this helps!