Difference in CGI and PHP?
May 24, 2002 by daynah
Filed under Daily Ramblings
Someone on a board asked what the difference between CGI and PHP. Here’s my explaination. Correct me if I’m wrong on any parts. :)
—–
CGI means common gateway interface. It can be written in any language, perl, c, c++, etc.
CGI is the standard way for interfacing with web servers. A way of generating data and letting people all around the world to get this infomation. A CGI program must also execute in real time and would have dynamic output as a result.
The biggest difference is that CGI is a technology used, (we’ll call this technology webpages) while PHP is a specific language that displays this technology (just like HTML).
I think the question is better phrase as, “What’s the difference between Perl and PHP?” Languages that uses cgi create new processes for every request they receive.
An example would be the old ikonboard. Everytime you refresh the page, or view a topic, or thread, a new process is generated. The idea can be compared to opening 20 different programs on your computer. These would be known as ‘processes.’ All these ‘processes’ require more memory on the computer/server so they can be executed. And because of that, many hosts are banning those types of scripts.
Let’s compare a process using a chatroom. Pretend you’re chatting and you need the Admin to answer your question before you can talk to a mod about something else. [Thanks for the analogy Michel :) ] This dependency is just how processes work. They won’t execute until the other ones are done. Hence the reason it can be slow.
PHP however, create threads. Threads are parts of the program that can execute independently of other parts. This means it doesn’t have to wait for one thread to run before it can run itself. Let’s use the chatroom for a thread example too. If you talk to person A and person B talks to person C, etc. you can consider all these threads of their own. Person A doesn’t need to talk to person B before they can talk to you. Each person is talking to someone else independently.
I hope your understanding of CGI, perl, and PHP is better. I don’t know if I explained it well enough or have I confused more people? heh Just post again if you need any part of this answered. :)


@






