|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
CGI Script PortabilityCGI programmers face two portability issues: platform independence and server independence. Platform independence is the capability of the code to run without modification on a hardware platform or operating system different from the one for which it was written. Server independence is the capability of the code to run without modification on another server using the same operating system. Platform IndependenceThe best way to keep your CGI script portable is to use a commonly available language and avoid platform-specific code. It sounds simple, right? In practice, this means using either C or Perl and not doing anything much beyond formatting text and outputting graphics. Does this leave Visual Basic, AppleScript, and UNIX shell scripts out in the cold? Yes, Im afraid so, for now. However, platform independence isnt the only criterion to consider when selecting a CGI platform. The speed of coding, the ease of maintenance, and the capability to perform the chosen task should also be considered. Certain types of operations simply arent portable. If you develop for 16-bit Windows, for instance, youll have great difficulty finding equivalents on other platforms for the VBX and DLL functions you use. If you develop for 32-bit Windows NT, youll find that all your asynchronous Winsock calls are meaningless in a UNIX environment. If your shell script does a system() call to launch grep and pipe the output back to your program, youll find nothing remotely similar in the Windows NT environment, unless you add an NT version of grep to the system. And AppleScript is good only on Macintoshes. If one of your mandates is the capability to move code among platforms with a minimum of modification, youll probably have the best success with C. Write your code using the standard functions from the ANSI C libraries and avoid making other operating system calls. Unfortunately, following this rule will limit your scripts to very basic functionality. If you wrap your platform-dependent code in self-contained routines, however, you minimize the work needed to port from one platform to the next. As you saw in the section Planning Your Script, when talking about encapsulation, a properly designed program can have any module replaced in its entirety without affecting the rest of the program. Using these guidelines, you may have to replace a subroutine or two, and youll certainly have to recompile; however, your program will be portable. Perl scripts are easier to maintain than C programs, mainly because no compile step is used. You can change the program quickly when you figure out what needs to be changed. And theres the rub: Although learning to write simple Perl is easier than learning C for many people, Perl has many obscure subtleties, and the libraries tend to be much less uniformeven between versions on the same platformthan do C libraries. You pay for all that wonderful string-processing and pattern-handling power. Also, Perl for Windows NT is fairly new and still quirky, although the most recent versions are much more stable. And in fairness to Perl, Win32 is not the only compiler or interpreter to be quirky on a relatively new operating system such as NT 4.0 and now 5.0. Server IndependenceFar more important than platform independence is server independence. Server independence is fairly easy to achieve, but for some reason, it seems to be a stumbling block to beginning script writers. To be server independent, your script must run without modification on any server using the same operating system. Only server-independent programs can be useful as shareware or freeware, and without a doubt, server independence is a requirement for commercial software. Most programmers think of obvious issues, such as not assuming that the server has a static IP address. The following are some other rules of server independence that, although obvious once stated, nevertheless get overlooked time and time again:
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |