More information about the Underscore mailing list

[_] Apache: Passing arguments to a CGI

Tom Gidden tom at gidden.net
Wed Feb 17 17:52:35 GMT 2010

Agreeing with Andy, here.

CGIs in C are possibly the worst way of doing it (no matter what 'it' is), and I've written CGIs in C, Perl and even Haskell and Awk.  If you're really, really locked into doing stuff in C, at least write them as Apache modules (although that's a whole other headache)

The behaviour you describe (eg. argv being odd) is completely expected.  CGIs were never meant to be the same as CLI apps.  Instead, you have to start looking at environment variables like getenv("QUERY_STRING"), as the QUERY_STRING (GET) isn't the only input of interest with a CGI (eg. stdin, PATH_INFO, and so forth).

To be honest, I'm slightly surprised it's giving you anything useful in argv, as I didn't know Apache did that.

If you're worried about messing with the server, may I suggest just installing PHP as a CGI?  It won't run as fast as the Apache module, but it'll be more self-contained:  you can do it within a user's home directory without root access, and just hashbang the CGI scripts.

The other thing to think about is that CGI puts a fairly large overhead on the machine, as every hit will include a fork() in addition to the child httpd.  Fine if truly internal, but if you're doing this from outside to inside, then hammering the outside machine might really bugger the inside machine.


Tom

-- 
Tom Gidden
http://gidden.net/tom