[thechat] C Programming and the web

deke web at master.gen.in.us
Tue May 28 06:21:00 CDT 2002

On 28 May 2002 at 0:45, Beau Hartshorne posted a message which said:

> I'm just getting into C programming. I understand that C is very fast,
> and very powerful. How difficult is it to get C programs to interact
> with a web page? With mySQL? Or with a PHP page? Or is this what Perl's
> for?

A CGI program is *extremely* simple. You read a GET from the URL, and
you read a POST from STDIN. You write the HTML output to STDOUT. You
need a routine that parses input, and once you have that written,
you're pretty much home free.

Interfacing with mySQL is no problem at all.

Running Perl or PHP scripts as CGIs means you have to load a mammoth
program into memory, then read in the script, then translate the script
into instructions which are executed. A program written in a compiled
language like C is much smaller, and because it's binary, it starts
running immediately.

If you aren't sharing your box with anyone else, you can get around
that by running Perl or PHP as Apache modules, but in a typical virtual
hosting setup, that means setting file permissions wide open, so that
any of the hosting company's tens of thousands of users can edit or
delete your files. Ouch!

The other advantage of a compiled CGI is security. Since you only link
in the code to do what you need to do, it's harder for an exploit to
get out of hand. That doesn't mean bad programmers with C are going to
write secure applications - just that a bad programmer with Perl or PHP
is a *real* hazard.

I hope you enjoy learning C. Good C programmers tend to be decent at
any other language they attempt, because they understand how the
machine "thinks" and learn how to organize their work. Try to teach a
BASIC programmer Java, or teach a Java programmer COBOL, and they are
often hopelessly lost, but a good C programmer is different.

  Do gravediggers qualify for "cost of living" raises?

More information about the thechat mailing list