CGI is dead, long live CGI
Yesterday's (not so pleasant) experience of trying to deploy Pastedance *) on an internal web server at work makes me appreciate the simplicity of CGI. CGI might be out of favor for production sites, but for personal and internal applications, it's still the best choice for me.
- There's no daemon. No slowly-but-ever-growing process that eventually gets killed or thrashes the server (thus, no need to configure ulimit/rlimit, or write another script to monitor this, or add a condition in code to exit periodically). No need to worry about memory leaks. No need to manage and monitor daemon process. No need to put startup script in cron, /etc/init.d/ or whatever. You can be as dirty or one-off as you want. (Of course, you don't always want to be dirty, but the fact that you can is great.)
- Works with any webserver. Works with any standard Linux server, like a plain Debian with Apache.
- Can be isolated easily. Run as each user. Run as nobody. Run as per-user nobody.
- Can be upgraded to FastCGI usually with very minor modifications (with caveat).
- You can run hundreds of applications/sites simultaneously on a single server. It's the shared hosting owner's dream.
- Did I mention there's no daemon? I can't tell you how much I, and fellow sysadmins, love it.
Unfortunately, Dancer is too slow if deployed as CGI. Each request takes one to a few seconds and this becomes unbearably slow since every image and CSS file is routed through it.
I am under the impression that CGI::Application is the only "current" web framework usable under CGI. But I understand that it's very minimal, perhaps even to my taste. If I were to write yet another web framework, one of my design goals would be to make it usable under CGI. But I really, *really* do not want to do that.
*) On another note, does anyone know of a pastebin webapp that you can install in 1-5 minute on a plain Debian server with Apache? Not necessarily need to be in Perl. Preferably runs under CGI and uses MySQL/PostgreSQL/plain text files.
Plack::Handler::CGI. Any PSGI-based web framework will do.
In fact, writing against raw PSGI is perfectly fine for small apps and I’ve done quite a bit of that.
Mojolicious is a full-stack web framework and damn fast as a cgi-script.
Running web apps as CGI has other issues as well, like making sure that permissions are set properly so you dont end up allowing joe douchebag to download proprietary information, ... but then again you wouldnt have that problem being a sysadmin, .... but as a sysadmin you should know that its super easy to configure apache to serve static dancer files directly instead of routing them through the script.
Hi Aristotle,
Yup, I tend to write PSGI apps too nowadays instead of CGI. The problem with most web frameworks is that they assume they will be a long-running process, so startup overhead doesn't matter. That makes them unusably slow if deployed as CGI.
Steven, Aristotle suggestion is that you can write PSGI apps without using a framework.
If I had to write a webapp that has to run on top of CGI, I would try Web::Simple for the dispatcher.
Challenge accepted...
Usage:
Meh, that link didn't work right. Try...
https://bitbucket.org/tobyink/web-paste-simple/src/tip/lib/Web/Paste/Simple.pm
Wow, that was quick. And more or less perfect. Just as minimal as the way I like it, with passable performance as CGI script.
Web-Paste-Simple-0.000_01 is now on CPAN.
Hi Steven
CGI::Snapp is the supported fork of CGI::Application.
Web::Simple seems like a potential solution that has (or will have) some vertical integration features with Dancer and Catalyst should you need to start scaling things up.
Do not forget about Mojolicious!
Yup, that's how I read it. I do write bare PSGI apps :)
Can you provide some numbers or benchmarks?
I tried the Mojo hello world described in its Synopsis:
and it needs around 0.3s to run, and loads about 104 modules/files totaling +- 35K lines of source code. While this is still bearable, it's hardly "damn fast as a cgi-script".
On the other hand, Mojo/Mojolicious does provide the convenient of automatic detection of CGI environment, so you don't need to write a separate dispatch CGI script by default. Plus it does not use Moose (potentially leaner). Plus it supports WebSocket. Seems like I will prefer it over Dancer.
Deploying Galileo is also much easier than Pastedance, although that is not reflective of anything, really.
Simple, quick to install, but moderately well featured pastebin application:
Stickey Notes - http://www.sayakbanerjee.com/sticky-notes/
It's written in PHP, but it's the nicest and easiest one I could find when I was looking for one to deploy for primarily personal use.
@Christopher: Thanks! Sticky Notes is nice indeed. Why can't Perl web apps be as simple as PHP to install/deploy? :-/