Wednesday, February 7, 2007

Assignment #4

CGI (Common Gateway Interface)

CGI is a very widely used standard for running external programs on a HTTP server. Like anything that is implemented on a computer, there are going to be problems and solutions to those problems everywhere. The following is a list stating some of these problems and solutions.

Coding a script wrong is probably one of the most common mistakes. If a CGI script doesn’t perform the way you expect it or you get an error message when executing it, then there is a problem somewhere. Another problem might be locating the error in your code. It could be that the script settings are incorrect, or your permissions are wrong. Make sure you double and triple check your code to make sure it will execute flawlessly. Another problem is that some scripts are too long, creating different problems. Testing and debugging is directly related to the size of the script. If the script size is manageable, then all related maintenance will also be manageable.

According to Webopedia, every time a new CGI script is run, it in turn starts a new process. This is bad news for slower older servers or high traffic servers. This will severely decrease the performance of your server. One solution to this problem is to use the server’s API (Application Program Interface). Using this aspect of the server will greatly increase the productivity since the applications are more integrated with the server. This also leads to a very large lag time between the server and the external program which can be somewhat fixed by keeping the CGI script in memory. This will only decrease the lag time, not eliminate it completely. Another time saving solution is to use cookies. Cookies will eliminate the unnecessary validations that must take place each time a page is accessed. Other problems include the fact that CGI scripts are stateless, meaning they exit as soon as their task is completed. Having to reconnect every time adds a considerable amount of time and has a large impact on performance. Scalability is also a problem when it comes to CGI since some systems can not handle a large number of processes started by each script.

There are ways to help ease the pain of these problems. One way is to use special CGI tools. A particular tool called CGI Tester will measure the performance of the scripts, along with statistics, error reporting, and server speed. Such tools will aid you in making your machine run at its best possible speed. Another solution that will help ease the pain of the server is to make the client-side do some of the work. JavaScript can be used to allow the browser to do some of the work, and also can be used for validation. You can also use the web server to keep the CGI scripts running all the time as co-processes. This way, when a script is called it will easily be able to complete its task without the lengthy start up time. This however puts a strain on the server’s memory, and utilities should be used to help reduce the stress on the machine.

Security is also a problem that must be addressed when using CGI. CGI is used to process user input, and this can be a very helpful addition to any website. However, users can trick CGI scripts into performing a command on the server which could result in a breach of your system. This can be remedied by using servlets. These servlets are used because they are not at risk of running forced, unintended commands. This will help prevent hackers from making their way into your system.

If you are going to use CGI scripts, you must understand how they work, and understand the risks that are involved. I believe CGI scripts are a good addition to an SOA, if they are used properly and are understood. Also, no script should be bigger than it has to be. The scripts should be kept to a smaller size to help in all aspects of coding and debugging. If there is extra code all over the place, it will appear messy, and it will surely show up when a customer tries to use your scripts. They could become unhappy with your service and you could lose them forever, just because you had too much going on at once. You must also make sure your server can handle the activities you want it to perform. If your site is heavily trafficked, you must have a server that will not collapse under all of the stress of running CGI scripts.


References

http://www.webopedia.com/TERM/C/CGI.html

http://www.k5n.us/article.php?id=0001


http://www.irt.org/articles/js172/index.htm#cgi_optimization

No comments: