Databases - Delphi Web Servers

The purpose of a Web Server is to generate a web page (html) that is displayed in a regular web browser.

A CGI Web Server is an *.exe file - ISAPI and NSAPI Web Servers are *.dll files.

*.dll Web Servers are better (faster and more efficient) for high volume sites, but they are very difficult to debug because the main Web Server (IIS, Netscape, and the like .. but not Apache) must be shut down each time a new *.dll is compiled. As a result, it is usually easier to create a CGI server first and convert it to an *.dll latter. (Only the project (*.dpr) file is different.) (Below, I provide an application that automatically shuts down IIS when new dll's are compiled.)

See C:\Program Files\BORLAND\Delphi5\Demos\Webserv for a demo where the CGI (*.exe) and ISAPI (*.dll) applications use a common module (*.pas file).

For an overview, see Creating Internet server applications in the Delphi help. (In the help contents, it is under Writing Distributed Application. You can also launch it via Start / Programs / Delphi / Help / Developing Distributed Applications, but then many of the links won't work.)

Running your program under IIS | Running your program under Apache | Testing | Passing Parameters


Running your program under IIS

To run your code under IIS, you must place it in a directory that has permission to execute programs. (Both CGI and ISAPI programs can share the same directory.)

The precise steps vary depending on which operating system and which version of IIS you are using.

On my XP system, each directory under

can be individually accessed and configured. I do not suggest assigning aliases to directories in that path - use aliases only if your executables are in another path.

For instance,

are accessed in a browser as If the web server is not on the local machine, but it is on the local intranet, replace localhost with either the machine name or it IP address. To simplify debug, you want Delphi to automatically store the compiled output in the appropriate directory. To configure this, from the Delphi menu, set


Running your program under Apache on a Windows platform

In Windows, you can run Apache 2 ways

Apache will run CGI exe's and ISAPI dll's. However, because the ISAPI dll's are reloaded each time that they are called, they run at the same speed as an *.exe. (Thus, IIS is much faster.)

By default, all *.exe files should be placed in

In order to create your own directories, you need to modify one of 3 configuration files (your choice). This code works with *.exe files - but not with dll's. To enable ISAPI dll's, edit one of the configuration files and add However, I was never able to get ISAPI dll's to work in cgi-bin or any other alias created with ScriptAlias.

This code works with *.exe files and *.dll files.

(For debug, you can add All or Indexes to the Options command - but don't leave it on a production machine.)

After modifying a configuration file, you need to restart Apache. Assuming that Apache is being run from a command prompt, running the following command in a separate command window will restart it. (In addition, the Service Name option is required when Apache is run as a service.)

Sometimes, the restart is not reliable - you must actually, close the Apache window and then restart it.

To simply test a configuration file, use


Testing

The Delphi help says that CGI files are more difficult to test than *.dll's - I don't agree at all. First I create CGI executables, and, once those are tested, I convert them to ISAPI dll's.


How to automatically update dll's

Running Replace_dll.exe on a Windows XP based web server will automatically shutdown part of IIS each time you compile a new dll. Replace ISAPI dlls.zip contains the *.exe, instructions, and full source code.

How it works - This Delphi program checks a sub-directory every 5 seconds. When a file is found, it shuts down the server and moves the file(s) to the main directory.

With this program, dll's are just as easy to test as CGI files.


Passing Parameters

There are basically 2 ways to pass parameters to a web server Because a single CGI or ISAPI web server can implement several actions, Delphi supports an additional syntax where /actionName goes between the CGI or ISAPI filename and the question mark.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Databases / Delphi / WebServers / WebServers.html