CGI scripts have always mystified me
Having used PHP as the logical choice for web development, I've always been a little mystified by cgi-bin scripts and never bothered to learn how they work. But no longer.
CGI scripts are nothing but scripts or executable programs. Apache simply executes them and renders the results. Of course, because every CGI program is an external application and requires the web server to start a new process, it makes the whole thing very processor intensive. The modern method of embedding scripts in web pages (most popularly PHP/ASP) which can be directly interpreted by Apache is a far more efficient method and I suppose more logical from a web designer's point of view.
However, there are still a few advantages to CGI scripts: you can use whatever language you wish to (plain shell scripting, Perl, Python and even compiled C executables). This offers many more options to the developer. Also in many cases CGI scripts are not limited to server "modules" and can directly use the underlying Operating System's functionality.
Rather than reinvent the wheel however, I'll point you to Apache's CGI tutorial which is a must read for any webmaster, web developer or server administrator.
Yes, CGI can be intimidating and complex CGI scripts can be a headache to maintain, but it's nevertheless useful to have an idea about how they work since so many websites still utilize this method of delivering dynamic content.
14 comments
I'm currently learning python and might start diving into some mod_python for apache as well, really liking it over learning/getting better with Perl.
In general, Python's documentation sucks. That is the biggest impediment to using that language instead of, say PHP or even Perl.
It was recommended by my boss as the better of the books to learn Python. You can read the entire thing online or download it. I also purchased it cause I'm weird like that and like hard copies of things when I'm away from a computer.
I feel it's more natural to use Python just as a plain programming language as it's intended to be and then use the modules required for web programming rather than learn another "framework" which has its own set of implementation rules.
I've already written a Python script to generate a website using text files.
While I believe Python and Perl have a lot of advantages over PHP going a bit deeper into them, PHP allows a lot of "lazy coding" too and is specifically targetted at "web designers" rather than "programmers". The biggest draw of PHP is its ability to be used as an embedded language so that it becomes very convenient to work around non-interpreted code (most commonly HTML or XML). Python and Perl for web development are not so intuitive but I think once you learn to use them, they can offer much more power and more maintainable code.
Python and Perl are much more traditional programming languages and web development is just one aspect of them.
I don't want to be some master programmer, but knowing a little bit of these help my career as a systems administrator.
Think of it this way: PHP, ASP, JSP... etc. are languages that are embedded in documents (mostly HTML) and interpreted by the web server software directly (or through extensions like mod_php for Apache etc.)
CGI scripts are real programs (or scripts) that are called by the server software to run as a separate process and their output is returned to the server which then serves that as a web page.