
 Back To Article
December 7, 2001 01:01 PM PST
Are you down with PHP?
Tom Yager
DEVELOPERS CREATING scripted, dynamic Web applications have an embarrassment of riches in programming languages to choose from, although the choices may sometimes be limited by the platform. For example, WebSphere developers work in Java, whereas IIS coders tend toward Microsoft's JScript and VBScript languages. But when a company uses Apache to host a Web site, Web programming can be done in countless languages. Along with Perl, the open-source PHP (Hypertext preprocessor; originally Personal Home Page) language has emerged as a favorite of Apache developers.
PHP's easy-to-learn syntax, strong database connectivity, broad platform compatibility, and huge base of contributed extensions account for its large and growing base of users. PHP Version 4 sweetened the pot with multithreaded Web-server support, buffered output, and an optimized execution engine, among many other added features. The June release, 4.0.6, repairs bugs and tweaks performance further still. This release, as were those before it, is free and open-source, so companies can exploit PHP's technical strengths and lower their operating costs at the same time.
Whereas Apache is the Web server of choice for PHP developers, users of other servers needn't switch to use the language. PHP has been packaged as an extension to Netscape/iPlanet and Microsoft commercial Web servers. When running under Windows, PHP 4 fits into its hosting server's multithreaded architecture, improving the performance and lowering the resource burden of PHP applications. Recognizing that Windows users often lack C development tools, PHP's authors offer the Windows version of the PHP language interpreter in binary form. Unix, Linux, and BSD releases are distributed as source code.
Among PHP's strengths is its capability for driving just about any database. The open-source MySQL database is often bundled with PHP and is even included in some Windows binary distributions. In addition to MySQL, PHP directly supports Oracle, Sybase, Informix, SQL Server, and others, as well as databases reachable via ODBC.
PHP has a dedicated group of functions for each database type, making migration across databases challenging unless you rely on ODBC. A PHP extension called Metabase provides a unified programming interface to most popular commercial and open-source databases.
On the Windows platform, PHP can create and call any COM object that exposes an IDispatch (script-compatible) interface. Similarly, if the Java run time is installed on a Windows or Unix/Linux/BSD server, PHP can instantiate and call into Java classes.
In our tests, we found that one of PHP's few limitations is that the lifetime of COM and Java objects is limited to a single Web page; that is, after the page is fully rendered in the client, the object instance is destroyed.
PHP does support the concept of session variables that persist across multiple Web pages, but COM and Java objects cannot be stored as session variables. Any such objects that are part of a multipage operation, such as a shopping cart, must be reconstructed at the top of each page. This limitation affects database connections as well, but at least one contributed database library, ADODB for PHP, manages to preserve database connections across multiple pages. Because PHP has so many active users, limitations exist only until someone in the community creates a work-around.
PHP's language syntax is a cross between C and Perl. It's easy for any C/C++, Java, JavaScript, or Perl programmer to adapt his or her skills. In our opinion, PHP ranks near the top in ease of use, and consequently, speed of coding. VBScript is the only language that might be easier for new programmers to learn, and it's not nearly as versatile or extensible as PHP.
Developers will be impressed by PHP's huge library of built-in data types and functions. Arrays can be simple or associative, accepting either lists of items or associated key/value pairs. Character strings are an intrinsic data type, and the language's string-handling facilities are strikingly similar to the string functions in the C standard library. PHP is not an object-oriented language per se, but it supports user-defined classes and simple inheritance. Uniquely, arrays can be converted to objects so that the array's keys become object properties.
There are few roles that PHP, aided by its many extensions, can't fulfill. Object-programming adherents may point to PHP's limited object support -- it is missing destructors, private members, and multiple inheritance, among other things -- as limiting PHP's usefulness in complex projects.
PHP lacks inherent support for transactions, but it can handle an SQL database transaction as long as all the transaction code fits on a single Web page. And although there are XML-RPC and SOAP (Simple Object Access Protocol) extensions, PHP can't transform objects into Web services as effortlessly as .Net can. But as long as architects and coders can work within and around these constraints, PHP deserves consideration as a low-cost, quick-turnaround alternative to Active Server Pages and Java.
Technical Director
|