⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch01_03.htm

📁 用perl编写CGI的好书。本书从解释CGI和底层HTTP协议如何工作开始
💻 HTM
字号:
<?label 1.3. Alternative Technologies?><html><head><title>Alternative Technologies (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch01_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch01_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">1.3. Alternative Technologies</h2><p>As its title suggests, this book focuses on CGI programs written inPerl. Because Perl and CGI are so often used together, some peopleare unclear about the distinction. <a name="INDEX-72" /> <a name="INDEX-73" />Perl is a programming language, and CGI is aninterface that a program uses to handle requests from a web server.There are alternatives both to CGI and to Perl: there are newalternatives to CGI for handling dynamic requests, and CGIapplications can be written in a variety of languages.</p><a name="ch01-4-fm2xml" /><div class="sect2"><h3 class="sect2">1.3.1. Why Perl?</h3><p>Although CGI applications can be written in any almost any language,Perl and CGI scripting have become synonymous to many programmers. AsHassan Schroeder, Sun's first webmaster, said in his oft-quotedstatement, "Perl is the duct tape of the Internet." Perlis by far the most widely used language for CGI programming, and formany good reasons:</p><ul><li><p>Perl is easy to learn because it resembles other popular languages(such as C), because it is forgiving, and because when an erroroccurs it provides specific and detailed error messages to help youlocate the problem quickly.</p></li><li><p>Perl allows rapid development because it is interpreted; the sourcecode does not need to be compiled before execution.</p></li><li><p>Perl is easily portable and available on many platforms.</p></li><li><p>Perl contains extremely powerful<a name="INDEX-74" /><a name="INDEX-75" />string manipulation operators, withregular expression matching and substitution built right into thelanguage.</p></li><li><p>Perl handles and manipulates binary data just as easily as it handlestext.</p></li><li><p>Perl does not require<a name="INDEX-76" /><a name="INDEX-77" />strict variable types;<a name="INDEX-78" /> <a name="INDEX-79" /><a name="INDEX-80" />numbers, strings, and booleans aresimply scalars.</p></li><li><p>Perl interfaces with external applications very easily and providesits own filesystem functions.</p></li><li><p>There are countless <a name="INDEX-81" /> <a name="INDEX-82" /><a name="INDEX-83" />open source modules for Perl availableon <a name="INDEX-84" />CPAN, ranging from modules for creatingdynamic graphics to interfacing with Internet servers and databaseengines. For more information on CPAN, refer to <a href="appb_01.htm">Appendix B, "Perl Modules"</a>.</p></li></ul><p>Furthermore, Perl is fast. Perl isn't<a name="INDEX-85" /><a name="INDEX-86" />strictly an interpretedlanguage. When Perl reads a source file, it actually compiles thesource into low-level opcodes and then executes them. You do notgenerally see compilation and execution in Perl as separate stepsbecause they typically occur together: Perl launches, reads a sourcefile, compiles it, runs it, and exits. This process is repeated eachtime a Perl script is executed, including each time a CGI script isexecuted. Because Perl is so efficient, however, this process occursfast enough to handle requests for all but the most heavilytrafficked web sites. <a name="INDEX-87" /> <a name="INDEX-88" /> <a name="INDEX-89" />Note that this is considerably lessefficient on Windows systems than on Unix systems because of theadditional overhead that creating a new process on Windows entails.</p></div><a name="ch01-5-fm2xml" /><div class="sect2"><h3 class="sect2">1.3.2. Alternatives to CGI</h3><p>Several <a name="INDEX-90" />alternatives to CGI have appeared in recentyears. They all build upon CGI's legacy and provide their ownapproaches to the same underlying goal:<a name="INDEX-91" /><a name="INDEX-92" />responding to queries andpresenting dynamic content via HTTP. Most of them also attempt toavoid the main drawback to CGI scripts: creating a separate<a name="INDEX-93" /><a name="INDEX-94" /><a name="INDEX-95" />process to execute the script every time itis requested. Others also try to make less of a distinction between<a name="INDEX-96" />HTML pages and code by moving code intoHTML pages. We'll discuss the theories behind this approach in<a href="ch06_01.htm">Chapter 6, "HTML Templates"</a>. Here is a list of some of the majoralternatives to CGI:</p><dl><dt><b>ASP</b></dt><dd><p><a name="INDEX-97" /><a name="INDEX-98" />Active Server Pages, or ASP, wascreated by Microsoft for its web server, but it is now available formany servers. The ASP engine is integrated into the web server so itdoes not require an additional process. It allows programmers to mixcode within HTML pages instead of writing separate programs. Aswe'll see in <a href="ch06_01.htm">Chapter 6, "HTML Templates"</a>, there are modulesavailable that allow us to do similar things using CGI. ASP supportsmultiple languages; the most popular is Visual Basic, but JavaScriptis also supported, and ActiveState offers a version of Perl that canbe used on Windows with ASP. There is also a <a name="INDEX-99" /><a name="INDEX-100" />Perl module, Apache::ASP, thatsupports ASP with <em class="emphasis">mod_perl</em>.</p></dd><dt><b>PHP</b></dt><dd><p><a name="INDEX-101" /><a name="INDEX-102" /> <a name="INDEX-103" /> <a name="INDEX-104" />PHP is a programming language that issimilar to Perl, and its interpreter is embedded within the webserver. PHP supports embedded code within HTML pages. PHP issupported by the Apache web server.</p></dd><dt><b>ColdFusion</b></dt><dd><p><a name="INDEX-105" /><a name="INDEX-106" />Allaire's ColdFusion<a name="INDEX-107" /> <a name="INDEX-108" />creates more of adistinction than PHP between code pages and HTML pages. HTML pagescan include additional tags that call ColdFusion functions. A numberof standard functions are available with ColdFusion, and developerscan create their own controls as extensions. ColdFusion wasoriginally written for Windows, but versions for various<a name="INDEX-109" /> <a name="INDEX-110" />Unix platforms are now available as well.The ColdFusion interpreter is integrated into the web server.</p></dd><dt><b>Java servlets</b></dt><dd><p><a name="INDEX-111" /><a name="INDEX-112" /><a name="INDEX-113" /><a name="INDEX-114" />Java servlets were created by Sun. Servletsare similar to CGI scripts in that they are code that createsdocuments. However, servlets, because they use Java, must be compiledas classes before they are run, and servlets are dynamically loadedas classes by the web server when they are run. The interface isquite different than CGI. JavaServer Pages, or JSP, is anothertechnology that allows developers to embed Java in web pages, muchlike ASP.</p></dd><dt><b>FastCGI</b></dt><dd><p><a name="INDEX-115" /><a name="INDEX-116" />FastCGI maintains one or more instances of<tt class="command">perl</tt> that it runs continuously along with aninterface that allows dynamic requests to be passed from the webserver to these instances. It avoids the biggest drawback to CGI,which is creating a new process for each request, while stillremaining largely compatible with CGI. FastCGI is available for avariety of web servers. We'll discuss FastCGI further in <a href="ch17_01.htm">Chapter 17, "Efficiency and Optimization"</a>.</p></dd><dt><b>mod_perl</b></dt><dd><p><em class="emphasis">mod_perl</em><a name="INDEX-117" /><a name="INDEX-118" /><a name="INDEX-119" /> is a module for the Apache webserver that also avoids creating separate instances of<em class="emphasis">perl</em> for each CGI. Instead of maintaining aseparate instance of <tt class="command">perl</tt> like FastCGI,<em class="emphasis">mod_perl</em> embeds the<tt class="command">perl</tt><a name="INDEX-120" /><a name="INDEX-121" /> <a name="INDEX-122" /> <a name="INDEX-123" /> interpreter inside the webserver. This gives it a performance advantage and also gives Perlcode written for <em class="emphasis">mod_perl</em> access toApache's internals. We'll discuss<em class="emphasis">mod_perl</em> further in <a href="ch17_01.htm">Chapter 17, "Efficiency and Optimization"</a>.</p></dd></dl><p>Despite a <a name="INDEX-124" />proliferation of these competingtechnologies, CGI continues to be the most popular method fordelivering dynamic pages, and, despite what the marketing literaturefor some of its competitors may claim, CGI will not go away any timesoon. Even if you do imagine that you may begin using othertechnologies down the road, learning CGI is a valuable investment.Because CGI is such a thin interface, learning CGI teaches you howweb transactions works at a basic level, which can only further yourunderstanding of other technologies built upon this same foundation.Additionally, CGI is universal. Many alternative technologies requirethat you install a particular combination of technologies in additionto your web server in order to use them. CGI is supported byvirtually every web server "right out of the box" andwill continue to be that way far into the future.</p></div><hr align="left" width="515" /><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch01_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td width="172" valign="top" align="right"><a href="ch01_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td width="172" valign="top" align="left">1.2. Introduction to CGI</td><td width="171" valign="top" align="center"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td width="172" valign="top" align="right">1.4. Web Server Configuration</td></tr></table></div><hr align="left" width="515" /><img src="../gifs/navbar.gif" alt="Library Navigation Links" usemap="#library-map" border="0" /><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area href="../index.htm" coords="1,1,83,102" shape="rect" /><area href="../lnut/index.htm" coords="81,0,152,95" shape="rect" /><area href="../run/index.htm" coords="172,2,252,105" shape="rect" /><area href="../apache/index.htm" coords="238,2,334,95" shape="rect" /><area href="../sql/index.htm" coords="336,0,412,104" shape="rect" /><area href="../dbi/index.htm" coords="415,0,507,101" shape="rect" /><area href="../cgi/index.htm" coords="511,0,601,99" shape="rect" /></map></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -