home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

Programming PHPProgramming PHPSearch this book

15.2. Writing Portable Code for Windows and Unix

One of the main reasons for running PHP on Windows is to develop locally before deploying in a production environment. As most production servers are Unix-based, it is important to consider porting[10] as part of the development process and plan accordingly.

[10]For an excellent article on porting between Windows and Linux for many of today's scripting languages, see "Linux to Windows 2000 Scripting Portability," available on the Microsoft developer's web site at http://www.microsoft.com/technet/treeview/default.asp?url=/TechNet/prodtechnol/iis/deploy/depovg/lintowin.asp. Much of this discussion was abstracted from that paper.

Potential problem areas include applications that rely on external libraries, use native file I/O and security features, access system devices, fork or spawn threads, communicate via sockets, use signals, spawn external executables, or generate platform-specific graphical user interfaces.

The good news is that cross-platform development has been a major goal in the development of PHP. For the most part, PHP scripts should be easily ported from Windows to Unix with few problems. However, there are several instances where you can run into trouble when porting your scripts. For instance, some functions that were implemented very early in the life of PHP had to be mimicked for use under Windows. Other functions may be specific to the web server under which PHP is running.

15.2.5. Server-Specific Functions

If compiled as a plug-in for Apache, PHP includes several functions that are specific to the Apache web server. If you use these functions, and are porting your scripts to run under IIS, you will need to reimplement that functionality. Following are the Apache-specific functions and some solutions for replacing them:

getallheaders( )
Fetch all HTTP request headers. You can access the HTTP request headers via the predefined variable $HTTP_ENV_VARS instead of using this function for any web server, including Apache.

virtual( )
Perform an Apache subrequest. This function allows you to include a URI from the local web server in the PHP script. If the retrieved text includes a PHP script, that script will become part of your current script.

apache_lookup_uri( )
Perform a partial request for the specified URI and return all information about it. This function requests Apache to provide information about a URI. No conversion is available for IIS.

apache_note( )
Get and set Apache request notes. This function is used for communication between Apache plug-ins. No conversion is available for IIS.

ascii2ebcdic( ) and ebcdic2ascii( )
These functions translate strings to and from ASCII and EBCDIC. Apache must be compiled with EBCDIC support for these functions to work. PHP provides no other means of converting EBCDIC strings. Microsoft provides a C-based API to handle EBCDIC translations.

There is also a set of IIS-specific functions, though its purpose is primarily for management of IIS.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.











??????????????@Mail.ru