December 2009 Archives

The Problems With CGI

The Common Gateway Interface was revolutionary. It gave us, for the first time, an extremely simple way to provide dynamic content via HTTP. It was one of a combination of technologies that led to the explosive growth of the Web. For anyone writing an application that runs once per HTTP request, there is no other practical option. And for such applications, CGI is almost always adequate.

But modern web applications typically run in persistent environments. For anything with more than a small trickle of traffic, we don't want the overhead of launching a new process for every hit. Even in low-traffic environments, the startup costs involved with using modern Perl frameworks like Moose and DBIx::Class can make non-persistent applications prohibitive.

We have things like mod_perl and FastCGI for easily creating persistent applications. But these applications are generally built upon emulating aspects of the stateless, non-persistent CGI protocol within a persistent environment. Even pure mod_perl applications typically receive much of their input via environment variables specified in the CGI standard, often by instantiating CGI.pm or one of its clones.

This model is fundamentally broken. Read on for my list of reasons why CGI should not be used in persistent applications.

That annoying non-self-closing <script> tag

This is a stupid hack and you shouldn't do it. But it was one of those things where I wondered if it would work and had to try it.

One of the things that annoys me tremendously about HTML is that you can't write a self-closing script tag. E.g.

<script type="text/javascript" src="/foo.js" />

is invalid. The <script> element is not allowed to be empty because it may contain inline code, and HTML is not smart enough to turn that feature on or off based on the presence of an attribute. (And it probably shouldn't be.) So you have to do <script ... ></script> every time.

Got my new nook. You are jealous

My fabulous new nook arrived today. The packaging was atrocious, as can be expected for any new electronic gizmo, but once I broke out the Jaws of Life and freed the nook from its captivity, I was very pleased indeed. The first thing I did was to load it up with my PDF copy of Mark Jason Dominus's Higher Order Perl, which is now available for free and which every Perl programmer should read once a year or so.

About Mike Friedman

user-pic Mike Friedman is a professional computer programmer living and working in the New York City area.