Run CGI scripts in own webserver

K

Kevin Kevin

Hello,

Does anybody know how I can run ruby cgi scripts in my web server. I
coded the webserver myself in ruby. At this moment I use ERB to parse
the .rhtml files. It all works fine but now i want to use the
functionality of CGI to extend my webserver. So I would like to read the
CGI file, parse it and send my html output to the user's webbrowser.

So does anybody knows how to run a CGI file?
 
A

andrew mcelroy

[Note: parts of this message were removed to make it a legal post.]

Hello,

Does anybody know how I can run ruby cgi scripts in my web server. I
coded the webserver myself in ruby. At this moment I use ERB to parse
the .rhtml files. It all works fine but now i want to use the
functionality of CGI to extend my webserver. So I would like to read the
CGI file, parse it and send my html output to the user's webbrowser.

So does anybody knows how to run a CGI file?
CGI is part of standard lib. try ruby uses it (until i can get a sessions
issue worked out in rails).

Andrew McElroy
http://tryruby.org
 
P

Phillip Gawlowski

Hello,

Does anybody know how I can run ruby cgi scripts in my web server. I
coded the webserver myself in ruby. At this moment I use ERB to parse
the .rhtml files. It all works fine but now i want to use the
functionality of CGI to extend my webserver. So I would like to read the
CGI file, parse it and send my html output to the user's webbrowser.

So does anybody knows how to run a CGI file?

That depends on your webserver. Apache has the fast_cgi module, which
should help you in getting up to speed, if you use Apache. I'm certain
lighttp and NGinx have similar modules/plugins/whatever to facilitate
CGI.

And I think Ruby's Webrick HTTP server-cum-library should be able to
serve Ruby CGI scripts.

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 
A

Albert Schlef

Andrew Mcelroy wrote in post #988626:
CGI is part of standard lib. try ruby uses it (until i can get a

He can use Sinatra or some other Rack-based framework. Rack supports the
CGI interface. (Well, it's supposed to; I haven't actually tried it.)
This will save him the work of converting the code in the future if he
decides to move away from CGI.
 
A

andrew mcelroy

[Note: parts of this message were removed to make it a legal post.]

CGI is part of standard lib. try ruby uses it (until i can get a sessions
issue worked out in rails).

I should clarify that try ruby is open source:
http://github.com/sophrinix/TryRuby
the /public directory is the ruby CGI 1.9.2 based version. it will show you
how to write a ruby cgi website. I didn't mean that to come off as self
promoting as it may of sounded.

Andrew McElroy
http://TryRuby.org
 
P

Phillip Gawlowski

As the op stated, he wrote his own server.

Which I failed to parse completely. *d'oh*

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.
 
B

Brian Candler

Kevin DeValck wrote in post #988602:
Does anybody know how I can run ruby cgi scripts in my web server. I
coded the webserver myself in ruby.

You need to implement the (obsolete) CGI spec yourself in your server:
http://w3.org/CGI/
http://graphcomp.com/info/specs/cgi11.html
See also RFC 3875

You could spawn the process yourself using IO.popen, but the trouble is
setting the environment variables first in a thread-safe way. Probably
better to use IO.pipe, fork and exec. Look at the source for open3.rb in
the standard library.

I'm sure this will be an interesting learning exercise about how CGI
works, but most people have abandoned CGI anyway because it's hugely
inefficient. So if I were you, I'd be looking at Rack instead, or at
least FastCGI or SCGI.

HTH,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top