plik


Apache Server for Windows Little Black Book:The Apache API function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Apache Server for Windows Little Black Book (Publisher: The Coriolis Group) Author(s): Greg Holden with Matthew Keller ISBN: 1576103919 Publication Date: 01/01/99 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:   Previous Table of Contents Next Chapter 15The Apache API If you need an immediate solution to: Viewing Module Structure Using Common API Functions Using Pools Tracking Open Files In Brief The Apache API An application programming interface (API) is a set of programming commands that let you add functionality to an application. Apache has its own API; it provides programmers with a generalized interface so they can tap into or add to the abilities of the server. For the most part, the API is used to add code to the server through modules. As mentioned in Chapter 5, modules are miniature programs (or segments of programs) that help Apache perform a wide range of tasks. The fact that they are modular—that is, they can be enabled or removed via the configuration files—gives you a great deal of flexibility in extending Apache’s power to meet your particular server needs. This chapter briefly describes how the Apache API can be used to create modules for the Apache Web server. Why Learn The Apache API? There are lots of Apache modules available already. Why would someone want to learn the API and write new ones? The reasons are fairly diverse, but they all point back to expandability and optimization. Writing Apache modules allows you to optimize and/or add functionality to the Web server. Many programmers have created modules for Apache to implement handlers for specific data types that the server cannot process already and that cannot be handled directly through the common gateway interface (CGI). Here are some examples: •  mod_imap was created to handle image map functions. •  mod_include was written to enable Apache to parse server-side includes (SSIs) and to go beyond the previous NCSA-style SSI syntax. •  mod_usertrack succeeded mod_cookie to handle the placement of HTTP cookies to track user sessions. •  mod_log_config was created to enable developers to configure log files in many different ways. The popular mod_perl serves as an excellent example. The Perl scripting language has long been used throughout the Web to write powerful CGI programs (see Chapter 7). When a Perl CGI is called, the server must launch a new thread to handle it, spawn a copy of the Perl interpreter, execute the script, and send the results back to the client. With mod_perl, the Perl interpreter is started when Apache loads and is kept in memory. When a script is called for the first time, it is compiled and cached so that future calls to the same script will not need to be recompiled (unless the script was changed since the last execution). Not only does mod_perl help the scripts run faster, it also allows Apache modules to be written in Perl. mod_perl accomplishes both of the goals that module writers have: It provides both optimizations for Perl CGI programs and the added functionality of writing modules in Perl. What You Need To Know What, then, do you need to know to create modules with the Apache API? •  You need a good knowledge of C for “traditional” modules. •  You need a fairly good knowledge of how modules work. •  You also need to know the Apache API and have reference to its functions. How The API Works The primary source of information about the API is a single page on the Apache Web site (www.apache.org/docs/misc/API.html). This overview document is also available in the documentation that comes with Apache (C:\Apache\htdocs\manual\misc\API.html). The API is not as heavily documented as the directives and general configuration issues are. Most programmers download the Apache source and learn about the API and its functions by evaluating the code contained within the various modules. However, there are other sources of information about the API that should help the beginning programmer get started. Here are some suggestions: •  mod_example— This is a test module that is provided with Apache to demonstrate many examples of the Apache API. You have to convert mod_example to a DLL and compile it into the server with the LoadModule directive (see Chapter 5). •  Robert Thau’s notes—Thau was involved with the NCSA Web server httpd, on which Apache was based. His notes on the API are scattered around the Web; some are at www5conf.inria.fr/fich_html/slides/papers/PS7/P20/api1.htm. •  mod_perl notes—The Perl Developer’s Conference in the summer of 1998 included a presentation on mod_perl that addressed the Apache API; see perl.apache.org/tpc-2.0/advanced-modperl/slide1.html. •  “How to Hack Your Server ”—This article, written by Sameer Parekh for WEBsmith Online, provides another overview of how modules are structured and how to create your own (www.ssc.com/websmith/issues/i4/ws57.html). In our experience, the API is commonly implemented by reviewing the source files and evaluating the comments and header information within them. Requests And Handlers Apache handles requests from a client in a series of steps that are called phases. The Apache API provides a hook for each of these phases (the phases are described in more detail in Chapter 5). Apache looks at its modules to see if any has a handler for the request. The module can use one of the following methods to respond: •  Handle the request •  Decline the request •  Generate an error code How Handlers Work Handlers operate by taking as an argument a structure that describes a particular request that has been made to the server, called a request_rec structure. This structure contains pointers to a resource pool, pointers to other structures that contain per-server and per-connection information, and information regarding the request. Here are a few of the request_rec elements: •  connection— A pointer to the conn_rec structure, which describes the current local socket address and other details of the current connection. •  content_type—Contains the MIME type for the server to use when it is processing the request handlers. •  filename—Specifies the full path to an actual file in the file system. •  finfo—Contains information about the file if it can be found in the file system. •  headers_in— Points to a table structure that lists all of the incoming HTTP structures sent by the client to Apache. •  headers_out—Points to a table that contains headers sent by Apache back to the client. Previous Table of Contents Next 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.

Wyszukiwarka

Podobne podstrony:
301 11
296 297
301 304
301 01
14 (297)
301 13

więcej podobnych podstron