Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C and web programming?

Options
  • 10-03-2005 9:23pm
    #1
    Registered Users Posts: 4,276 ✭✭✭


    Howdy,

    Just curious is it possible to use C programs on the web? Like I know you can use C for CGI but is there any simple enough way of creating a c program and passing whatever is entered to a C program running?

    I've come across sites before that have files with .exe extensions. May just be for show or is it possible? Is it also possible to replace other web based language (PHP, ASP, CFM etc.) functionality such as cookies and database access with such a program?


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    I know you can use C with ISAPI. Is that what you're looking for?


  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Not too sure what I am actually looking for to be honest. Just might be handy to do :) I'll look into it. Thanks


  • Registered Users Posts: 515 ✭✭✭NeverSayDie


    Yeah, you can use C/C++ for whatever CGI work you want, here's an example of a library I stumbled across, handles the environment variables and GETS and POSTS and such like: link


  • Registered Users Posts: 261 ✭✭HaVoC


    if your using c++ there is:
    Cgi++
    Bobcat(C++ implemententation of a java servlet) you'll have to pay for this though


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    There's a few ways of using C and/or C++ (RANT: these are NOT the same things, and C is NOT a subset of C++!) for web programming.

    The first and most obvious is as a straight CGI program. You can either use CGI libraries for C (google for them) or write your own (if you're a masochist). The question is, why would you want to do this? Such a program will almost certainly be slower than an equivalent PHP one (PHP is generally run as part of the web server; as such you do not incur the expense of process creation). If you have a specific library which you want to use in a web app, and which can't easily be reproduced, then this MAY be a solution, but see below.

    To do C CGI, you will need a web host that allows this (many don't) and access to a compiler that produces binaries for the webserver's platform (easy if the webhost is a 386 running Linux, not so easy if it's a large horrible IBM thing, for instance). If you have shell access to the machine, there may be a compiler there you can use. Web programming with C++ is a very bad idea. C++ implementations change quickly; try compiling something from the 90s on a modern compiler, and see how far you get. If your webhost upgrades their libc++ or whatever libraries, your program may stop working, and may ever require modification before it can be recompiled. Libaries are more of a problem in general writing in C for the web than they are for normal web languages. You can't compile programs statically, because they'll be huge and slow-loading. But the web host can (and probably will) change it's own libaries from time to time. You'll notice that I've only really discussed UNIX so far. This isn't (just) because I'm a smug UNIX user; ANY type of CGI in Windows is a bad idea, because of the high cost of process creation. When was the last time you saw "http://www.thing.com/cgi-bin/item.exe?a=b" as a URL?

    The next thing is FastCGI. This is fairly Apache-specific, as far as I remember, but does offer benefits in certain situations. It behaves similiarly to normal CGI, but runs the programs in the webserver's process. This speeds things up. Surprisingly few people use it, and few hosts support it.

    Then, there's webserver extensions. You can write these both for Apache and for IIS (ISAPI). The interfaces differ somewhat. These are run in-process, and can be very useful in certain situations, particularly when you need to produce certain pieces of interactive content very quickly. They're also nice in that you can leave server connections and such in memory (like in Java web servers, and PHP persistant DB connections). Microsoft apparently quartered the average load time of parts of Expedia by converting them from ASP to ISAPI, and hotmail is now written this way (http://www.securityoffice.net/mssecrets/hotmail.html). At least in Apache, you can also do all sorts of magic involving URLs with modules, if you want to. But these generally require direct access to the webserver; they are modifications to the server app itself and few webhosts will want you doing them. If you have a leased box (or virtual box ) you can do these. They are also of course, if written incorrectly, a huge security risk.

    Finally, you can write functions for PHP in C. This may be a nice, quick solution if you want to be able to use a specific C library, but have no other reasons to use C. You simply write wrapper functions, compile a module and add it to your php.conf. There's information on doing this stuff on the PHP website. The advantage of this is that languages like PHP and ASP are good at web-app tasks; if you use C exclusively for this, you may be needlessly re-inventing the wheel.

    If you are writing a web-app in C, then you may be interested in using the MySQL C API. It's poorly documented, but not difficult once you get the hang of it. Here's a tutorial: http://synnottsoftware.com/tutorials/mysql.html.

    Wow, that turned into a long post! Ah well...


  • Advertisement
  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Thanks a lot lots of information. No specific libraries that I wish to use. Just a learning experience :)

    I'd probably be using a *nix based enviroment for doing it as I have access to one with root etc. etc. Just pointed out the .exe web extension caus it is easier to notice :D


Advertisement