Hey everyone, after a VERY short time searching on google and these forums, i decided to put this question. But the question is too vague, so i have to expand on it:
When i first learnt PHP, the one who told me about web programming taught me that the client requests something from the server (Apache...), it processes the thing (PHP file) and sends it to the client.
This explanation is pretty right - and it lets you write PHP scripts.
But i know nothing of how servers internally work. I have no idea how to 'set up a server' (Like, i needed something for Comet, Reverse Ajax and somebody told me about 'setting up the server' but i know NOTHING about that).
Given that i know nothing about the gears within a server, i also don't know what exactly is CGI. What i do know is that it's similar to PHP - a file gets processed and the result is sent to the client. I've even seen a C file compiled into a CGI script.
(BTW and WAIT A SECOND[WAS? new acronym?]: HOW exactly does "printf" [if i recall correctly] map to printing stuff on a page? Who does that? How is that done? How does compiled machine code map to a webpage response??). But that is C, let's go onto Perl and Python.
They are interpreted, so no compilation is needed. But still.
How does CGI work?
An a-little-more-in-depth response would be really appreciated,
Thank you very much.
7 replies to this topic
#1
Posted 20 January 2011 - 02:18 PM
|
|
|
#2
Posted 20 January 2011 - 08:50 PM
How CGI works? Well it's like the web server execute the CGI script/executable through console, read the output, then pass the output back to its clients. Simply put, CGI scripts/executables are simply CLI scripts/executables. The web server executes them through shell console (using StdOut interface) and read the output through the same means (StdIn).
Edited by LuthfiHakim, 30 January 2011 - 06:15 AM.
Fix typo
#3
Posted 22 January 2011 - 01:26 AM
It sounds well, but i think i would need even a more in-depth explanation which should encompass more server-related concepts & stuff. Thanks !
#4
Posted 28 January 2011 - 02:01 PM
You basically get information from the user in either a URL-encoded format string or in raw data from a POST request. You can read that, and then you write an HTTP response (usually in HTML) and send that back to the user by writing to STDOUT.
sudo rm -rf /
#5
Posted 28 January 2011 - 05:56 PM
I don't know if you know HTTP, but I though I'd post this URL anyway: HTTP Made Really Easy
The way I understand it is that the server works something like this:
1. Wait for an incoming connection.
2. Receive the request (I don't exactly know how the server knows when to stop receiving, though).
3. If the file is executable:
a. Write the request to a file.
b. Call the executable file with hStdIn set to the read handle for the file with the HTTP request.
c. Send the contents of the file from hStdOut back to the client.
4. If the file is not executable then process the request using default settings (I think it's send the HTTP headers + "\r\n\r\n" + the contents of the file requested back to the client.
5. Finish servicing this request.
I am not totally sure, but that's what I understand so far.
The way I understand it is that the server works something like this:
1. Wait for an incoming connection.
2. Receive the request (I don't exactly know how the server knows when to stop receiving, though).
3. If the file is executable:
a. Write the request to a file.
b. Call the executable file with hStdIn set to the read handle for the file with the HTTP request.
c. Send the contents of the file from hStdOut back to the client.
4. If the file is not executable then process the request using default settings (I think it's send the HTTP headers + "\r\n\r\n" + the contents of the file requested back to the client.
5. Finish servicing this request.
I am not totally sure, but that's what I understand so far.
#6
Posted 29 January 2011 - 12:26 AM
#7
Posted 30 January 2011 - 06:18 AM
LuthfiHakim said:
...The web server executes them through shell console (using StdOut interface) and read the output through the same means (StdIn).
Lol, I was telling in wrong order.. sorry folks haven't use them in quite long time :c-whistle:
#8
Posted 21 March 2011 - 02:03 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









