Optimizing Your Installation

I l @ ve RuBoard

Now that you have PHP installed and running, it's worth considering how you can optimize your installation.

CGI

During the installation process, I showed you how to install PHP as a CGI application. CGI, however, has its limitations.

CGI was developed as web pages began to make the transformation from static HTML pages to dynamic pages built from programming languages or database data. At the time, Perl and C were popular programming languages, but there was no easy way of linking these to a web server so that web pages could be created using a programming language.

CGI was developed as a common way of allowing the web server to pass requests for certain file types (such as C and Perl files) to external applications (such as a gateway). For example, Perl files end with the .pl extension, so all requests for .pl files from the web server are passed to the Perl interpeter. The same is done with PHP if you use CGI mode ”in other words, all requests for .php files from the web server are passed to the PHP interpreter. See Figure 2.32.

Figure 2.32. The CGI process.

graphics/02fig31.gif

Note

CGI and Perl are often confused because of the early relationship they had. However, CGI is not Perl, and Perl is not CGI. They are two different things.


I showed you how requests for PHP files are passed to the PHP interpreter when you mapped the .PHP file extension to PHP via the PHP.exe program in the "Microsoft Internet Information Server (IIS) 5.0" section earlier in this chapter.

Overcoming CGI Limitations

CGI can place great demands on resources. Every time the web server passes a file to an application via CGI, it must invoke that application for every request. The result is that each application needs memory and processor time to run. Therefore, a web server that is passing tens of thousands of CGI requests a day can quickly become overloaded.

UNIX/Linux systems have a way to deal with this problem. Instead of compiling the application (such as PHP) as a CGI module, you can compile it right into the web server. This is a common approach for Apache web servers, where, instead of suffering the overhead of CGI, Apache's own code can easily manage and handle requests within its own memory space.

This is not a viable solution for most Windows web servers (although it is possible with the Apache web server on both UNIX and Windows systems). However, there is a mechanism for accomplishing something very similar ” SAPI (Server Application Programming Interface).

A SAPI basically gives you the same effect as compiling a module directly into the web server. When creating a SAPI filter, the web server vendor gives you access to certain APIs so that the vendor's web server can run requests to your SAPI filter in managed memory space. In other words, a SAPI filter does not give you the large memory and processor overheads of a CGI application.

SAPI and PHP

PHP for Windows is available as both a CGI application and a SAPI application.

SAPI is a generic term . Just as there are different web servers, so there are different SAPI applications.

Note

The extension list provided is missing the phpsrvlt extension, which is the Java servlet version of PHP. Although it's not a SAPI extension, if you run Java servlets, it's well worth a look. However, note that it has known instabilities under Windows, so check the release notes before you install it.


The extension list includes the following:

  • Php4isapi: Internet Server Application Programming Interface (ISAPI), Netscape Server Application Programming Interface (NSAPI), the SAPI for IIS

  • Php4nsapi: NSAPI, the SAPI for Netscape web servers

  • Php4apache: Apache module SAPI

  • Php4aolserverL AOL server SAPI

PHP ISAPI

I will only cover how to install the PHP ISAPI extension here. The PHP documentation covers how to install the other SAPI extensions.

Note that Personal Web Server does not support ISAPI. ISAPI is for IIS 4 and IIS 5 web servers only. Also note that running PHP as an ISAPI filter is not as stable as running it as a module integrated into Apache, so it is not recommended for production environments.

To begin installing the PHP ISAPI extension for IIS 5.0, you must first load the Internet Services Manager as you did in the CGI installation. Select Start, Programs, Administrative Tools, Internet Services Manager (ISM).

Right-click Default Web Site and select Properties. Then select the ISAPI Filters tab, as shown in Figure 2.33.

Figure 2.33. The Default Web Site Properties dialog box.

graphics/02fig32.gif

Click the Add button. You see the Filter Properties dialog box, shown in Figure 2.34. In the Filter Name field, type PHP , and in the Executable section, type the path to the ISAPI directory (or click Browse). If you have been following the CGI installation, the path is C:\PHP\sapi\php4sapi.dll .

Figure 2.34. The Filter Properties dialog box.

graphics/02fig33.gif

The installation at this point is like the CGI installation. Click OK to close the Filter Properties dialog box, and then click the Home Directory tab, as shown in Figure 2.35.

Figure 2.35. The Default Web Site Properties dialog box.

graphics/02fig34.gif

Click Configuration. You see the Application Configuration dialog box, shown in Figure 2.36.

Figure 2.36. The Application Configuration dialog box.

graphics/02fig35.gif

Click the Add button. You see the Add/Edit Application Extension Mapping dialog box, shown in Figure 2.37.

Figure 2.37. The Add/Edit Application Extension Mapping dialog box, showing the mapping for .phpi extensions.

graphics/02fig36.gif

In the Executable field, select the path to the ISAPI extension you specified previously. You can also click Browse, but be sure to change the Files of type setting to Dynamic Link Libraries (*.dll).

In the Extension field, type the file extension you want PHP files to have. This can be .php, but if you want to run PHP files in both CGI and ISAPI modes, you must use a different file extension. For ISAPI files, I have typed .phpi.

To complete the installation, close the ISM and stop and then restart IIS. To do this, from the command line type

 Net stop w3svc 

This stops IIS. To restart it, type

 Net start w3svc 
Testing PHP ISAPI

You can test the PHP ISAPI extension using the test page you created earlier. Just rename the file so that its file extension matches the one you used for PHP CGI:

 testinstall.phpi 

If you run this script in your web browser, you should see that the Server API section reads ISAPI, as shown in Figure 2.38.

Figure 2.38. The testinstall.phpi script, showing that the ISAPI filter for PHP is working correctly.

graphics/02fig37.gif

Zend Optimizer

The Zend Optimizer is a free add-on product from Zend Technologies Ltd. that optimizes the code that the Zend compiler generates for faster execution. This lets you run your PHP code more quickly than normal without needing to change the code.

The Zend Optimizer currently is for PHP 4.0.6 running in CGI mode only. It is worth noting that the Zend Optimizer can be used across several OSs, including Windows, Linux, and Solaris. However, the installation steps covered here are for the Windows version of the Zend Optimizer. (Other OS procedures can be found on the Zend Technologies Ltd. web site at http://www.zend.com.)

Downloading the Zend Optimizer

To download the Zend Optimizer, first visit http://www.zend.com/store/products/zend-optimizer.php.

You need to register with the Zend Technologies web site before you can download the Zend Optimizer. Creating login details for the web site gives you access to other resources and downloads.

When you are presented with the download page, you must download the version of the Zend Optimizer that supports the version of PHP that you have installed.

Installing the Zend Optimizer

The Zend Optimizer is packaged for Windows as a zip file. Unzip this file to a directory of your choice (I recommend the C:\PHP\ directory that you set up earlier in this chapter.)

The directory name that the zip file creates contains the Zend Optimizer version, the version of PHP the Zend Optimizer is for, and the OS the Zend Optimizer is for. In our example, this is as follows :

 C:\PHP\ZendOptimizer-1.1.0-4.0.5-Windows-i386\ 

Please note that this will vary depending on what version of PHP you intend to target with the Zend Optimizer. I suggest that you rename this directory with a simpler name, such as

 C:\PHP\ZendOptimizer\ 

as shown in Figure 2.39. This simplifies the installation process.

Figure 2.39. The Zend Optimizer installation directory.

graphics/02fig38.gif

To complete the installation, you will need to alter the php.ini file. Open the php.ini file and add the following lines to the end of the file:

 zend_optimizer.optimization_level=15  zend_extension_ts="C:\PHP\ZendOptimizer\ZendOptimizer.dll" 

zend_extension should be set equal to the Zend Optimizer directory (such as C:\PHP\ZendOptimizer\ZendOptimizer.dll).

Unless you are using another of Zend Technologies' products, the Zend Encoder, you can add another line to your PHP file that helps you run your PHP files faster via the Zend Optimizer:

 zend__optimizer.enable_loader = 0 
Testing the Zend Optimizer

If you run the PHP test script you developed earlier in this chapter, you will see that Zend Optimizer information is displayed in your browser, as shown in Figure 2.40.

Figure 2.40. A test script showing that the Zend Optimizer is working correctly.

graphics/02fig39.gif

I l @ ve RuBoard


PHP Programming for Windows
PHP Programming for Windows (Landmark (New Riders))
ISBN: 0735711690
EAN: 2147483647
Year: 2002
Pages: 99

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net