Who needs a huge server and scripting environment to run a simple site? Just open a socket, read until the second space, dump the requested file and close the socket.
Just think about all the electricity and time wasted because of wastefully starting Apache, parsing a complex config file each time, sending the script to PHP where it is parsed for the millionth time, generate the output, apply transformations to the headers, sending it out, keeping the socket open just in case there is another request, all for the convenience of not having to compile a script.
Name:
Anonymous2014-10-13 3:18
Apache doesn't start each time the script is requested.
You can use something like nginx instead of apache which is a piece of shit.
Proper caching mechanisms and a separate daemon for the server-side script interpreter is more efficient than a naive implementation in C.
CGI starts the entire process each time, since the program dies after shitting out its output. The act of mapping the executable to memory and initializing all that it needs to serve the request is expensive if it needs to be done hundreds to thousands of times a second. You're raping the kernel with all those socket init/close calls, all the memory map calls, and all the cleanup it has to do each time the request is done.
Your idea of how a web server works is also idiotic. You can't just "dump the file". Especially if the content is dynamically generated. That's why shit like chunked encoding exists. You won't know how long the content is until it's generated, and if you generate the entire thing before starting to send then you're increasing memory usage a substantial amount, and adding delays to the transfer. If you're going to close the socket each time you finish sending data, this is also extremely inefficient since even the simplest page usually has stylesheet and a few images, so you're adding in 5+ socket open/close calls, all the handshake overhead and the recalculation of the sliding window each time since you've destroyed the socket at that point, instead of just doing what HTTP does and just leaving it open. It's not "just in case", 99% of the time there will be more than one request.