Develop Apache DSO using Kylix3

zhaozj2021-02-08  224

Develop Apache DSO using Kylix3

content:

Why use DSO very important version of the problem module to compile Apache Support DSO Development DSO Deployment DSO Instance Wizard Reference About the author

In the Linux area:

Tutorial Tools & Product Codes & Component Articles

Hou Guangmin (Wearebug@tang.com) January 2003

Kylix is ​​a very good integrated development tool under Linux (individual thinking is the most suitable for Windows programmers to turn to Linux). The development of Apache Dynamic Sharing Object (DSO) in the previous work has encountered many in development. Question, have been solved by exploiting, some experiences are shared, so as not to go to the way.

Why is the most important reason for DSO is efficient. Apache is modular design, so it can load a wide variety of server-side scripting interpreters to support dynamic web pages. I have developed CGI, but with the increase of page visits, CGIs don't look at it, I need to increase efficiency. Since the original amount of code is large, I basically can't rewrite PHP or JSP instead of them, so I chose to compile the most frequently called module into dynamic shared objects (DSO) .. There is also a reason that the CGI program is a short connection, and cannot save the status information of the user. If the DSO of the resident memory can be used, then this problem can also be solved. Very important version issues are very important to develop version issues in the DSO process in Kylix. Open source Apache update is very fast, Apache 1. * version and 2. * version of DSO format are different, must be considered. DELPHI6 / KYLIX2 compiled DSO is a corresponding Apache 1. * version. I am using Kylix3 and Apache2.0.43, and the official website of Borland said that Kylix3 does not support Apache2 DSO, which makes me depressed for a long time. Later, I knew that Delphi7 supported Apache2, and Delphi7's CLX technology is a cross-platform, which let me find a solution. Delphi7's DSO2 project To reference httpd2, apachetwohttp, and apachetwoApp, HTTP, ApacheHTTP, and ApacheApp, then copy the corresponding PAS file in the Delphi7 installation directory, stored in the source code directory of Kylix3 Next, then compile. I have viewed an excessive code, and there is a symbolic symbol compiled across platform conditions, so this approach is feasible. Module Working Principle Apache Module You can register them to provide a function of a repra called signal in Apache. The reply is a function that can be registered in Apache, and Apache can call the function in multiple phases in the request process loop. The call is usually registered as a special event handler for the process. Most Apache is a link provided by the module registration callback function is part of the HTTP request loop. Apache currently defines 11 request loop phases, and modules can register the callback function. They are sequentially: post-read, URL translation, head resolution, access control, authentication, authorization, MIME Type Check, Fixup, response, or satisfaction, logging, and clearing. Compiling Apache Support DSO Unfortunately, the default Apache configuration does not support DSO, so we must modify the configuration file and recompile it, I am done directly through the command line. This is not difficult, after unpacking the obtained httpd * .tar.gz file, enter the directory, type the following command:

./configure -ENABLE-SO

Make

Make Install

If there is a problem in the compilation process, check out the error information, usually there is no corresponding development package, and put the development package. The default is installed in the / user / local / apache2 / directory, if you have other configuration requirements, type ./configure -help you will see it. Developing DSO has a previous preparation, using Kylix development DSO is very simple, just choose to generate Apache DSO when establishing an engineering, and establishing a CGI, Kylix transparently transparently. In the project document, it is necessary to modify the following: the default project file (as an example of Websnap): Library Project1

Uses

WebBroker,

Apacheapp,

......

{$ R * .res}

Exports

Apache_Module Name 'Project1_Module'

.

.

Change the apacheapp in USES to ApachetWoApp, add httpd2, why don't you explain this? ^ __ ^. There is also a place to be modified to be httpd2.pas file, find a constant definition, change this constant module_magic_number_major to 20020903, so Apache2 recognizes this DSO, remember. Since DSO is a resident memory, it is not like the process of exiting all resources like CGI, so resource allocation and recycling is especially important. After obtaining the data in the database, you must remember to turn the database connection in the appropriate destructure function, and you must release the memory after you create some of the stack objects. Of course, no matter what kind of procedure developed, this is a qualified programmer should do. Debug DSO is a bit trouble, there is a present on the official website of Borland, but I use my method to debug, you can decide what method it uses. I will first make a CGI engineering debug, add a cycle in the entrance, and then use Kylix's own process capture function to capture the started CGI, and the loop flag position can continue to be executed. After the debugging is confirmed, the new DSO project is established, delete the original unit file of the project, and then add all unit files in the CGI project to this project to recompile. Deploying DSO Of course, you have to modify the Apache configuration file, do less than these operations under Linux. Enter the confed directory in the Apache installation directory, modify the httpd.conf file, add the following text:

LoadModule XXX Modules / YYY.so

SetHandler YYY-HANDLER

When you start Apache, you can enter the http: // hostname / zzz call you deployed DSO. The problem that needs attention is that XXX you know the name of the Apache module, where you can write project1_module, followed by the location of the module file, usually put it under Modules, YYY is the name of the generated SO file, It should be Project1.so here. If there are some SO files in the process of starting or running, you need to add the path where the STENV LD_Library_Path SO file is added in the configuration file. Example Wizard here I use classic HelloWord as an example, you can walk through the long road developed by Apache DSO through this example. Now through the above explanation, I assume that you have made your Apache support DSO, we will take this step by step by step. 1 Create a WebSNAP project file and choose Apache DSO. Named HelloWorldp.dpr2 Modify Source Code File

3 Modify the page file to output HelloWorld. See the picture below. If you want to complete other features, it is the same as a normal CGI. Here is just a simple small example and does not complete the real WebSnap work.

4 Compile this engineering Kylix's default settings to add a lib prefix for the DSO file you generated, so you can see a file libhellowordp.so where you save the project file, this is the generated DSO file. Copy this file to the modules subdirectory of the Apache installation directory. 5 Remove the Apache profile Enter the confed directory in the Apache installation directory, modify the httpd.conf file, add the following text:

LoadModule HelloWorld_Module Modules / HelloWorldp.so

SetHandler HelloWorldp-Handler

6 Excited moments arrived at me not exaggerated, when I experienced all kinds of errors, this is this feeling. Now restart Apache, type http: // your server name / hello, Hello is the text you contained in the configuration file, you can't compete with other CGIs already existing (I I have suffered from harm). If there is no problem, you will see the following:

Just these, this is just a beginning, then start your work, you will find that the development under Linux is also very interesting. It should be noted that case in Linux is sensitive, don't come over the bad habits under Windows, so you will delay a lot of time.

Reference:

"Linux Apache Web Server Administration Guide" You can find more development references here: http://www.thedelphimagazine.com/ About Linux, there are many Chinese references in IBM DeveloperWorks.

About the author: Hou Guangmin, curious about the unknown affairs programmers, floating in Beijing. Currently using Kylix's Web development under Linux, Java is used to develop work. My email wearebug@etang.com, do not advertise and spam, thank you.

转载请注明原文地址:https://www.9cbs.com/read-2908.html

New Post(0)