PHP was created in 1995 by Rasmus Lerdoff, a 38-year-old from Greenland. Zeev Suraski and Andi Gutmans later worked with him to create PHP 3. Eventually, Zeev and Andi formed Zend Technologies, the name being a combination of letters from their first names.
Zend is responsible for bringing PHP to the System i. The company claims that PHP is "the most widely used programming language on the Web." The usage statistics for PHP, compiled by Netcraft, show that it is in use on over 20 million domains at more than 1.2 million IP addresses. And those are just the publicly visible domains. It is probable that it is also in broad use on private intranets. With these numbers in mind, it's no wonder an IBM representative recently told me, "We feel like we are just joining a party that everyone else was invited to long ago." He was referring to the recent development of PHP now being available on the System i.
What Is PHP?
PHP stands for PHP:Hypertext Preprocessor, an acronym that actually is a private joke shared among the "in crowd," because it's a recursive acronym; PHP is in the definition of PHP itself. I suppose this reflects its geeky origins, which are both its strength and its weakness.
PHP is actually several different things rolled into one. It is a formal language specification, an implementation of that specification, and a Web server plug-in (or Apache module). On the iSeries, the Apache module is supplied by Zend. The table below demonstrates how you might compare it to two other popular Web implementations on the System i.
|Popular Web Implementations |
|PHP ||CGI ||Java |
|Web Server ||Apache ||Apache ||WebSphere |
|Protocol ||PHP License ||CGI ||Java |
|Middleware ||Zend Core ||CGI Extension ||WebSphere WAS |
|Language Environment ||Apache Module ||I5/OS (usually ILE objects) ||Java Virtual Machine |
PHP is open source, and the typical license is free (although there are restrictions on its redistribution). As such, it is part of a commonly used open-source development and deployment environment that is often referred to by the acronym "LAMP," meaning Linux-Apache-MySQL-PHP.
Other than the hardware, the following are all the components necessary to run a dynamic, database-driven Web site: Linux for the operating system, Apache as the Web server, MySQL for the database engine, and PHP as the Web language. On the System i, you might refer to it as SAMP, if you substitute "System i" for "Linux," although this is not nearly so clever-sounding as LAMP. Note that PHP is an alternative method to delivering Web pages via CGI or Java, so you don't program PHP with CGI or CGIDEV2, Net.Data, or JavaServer Pages (JSP). You can, however, mix and match technologies when you deploy your Web site. So PHP programs can link to CGI programs and vice versa.
PHP is a hybrid scripting/compiled language. Like Visual Basic, PHP is generally interpreted as it is executed. This means the code is parsed and syntax-checked on the fly, as Web-page requests are made. Critics of this approach claim that the interpretive nature of PHP results in performance issues, compared with using compiled programs such as RPG CGI programs. However, Zend also provides a caching mechanism that will store previously executed code in a pseudo-compiled mode, which helps performance.
In any Web application, database access code can have a significant impact on performance. For example, if an SQL statement uses a complex join that requires building an entire access path from scratch every time, that is likely to have much more impact on performance than the fact that the PHP code itself is interpreted.
Wikipedia describes PHP as an imperative, object-oriented, functional language. This means you can write it when using procedural programming techniques (as you would in RPG or COBOL) or when using object-oriented techniques (as you would in Java, C++, or other object-oriented languages). The object-oriented features are a relatively new addition, not included until PHP 5 was released in July 2004.
How Programs Are Structured with PHP
PHP uses a similar program structure to that of other Web languages/tools such as ASP (Microsoft's approach), ColdFusion, or JSP. This generally involves interleaving server-side code with your presentation code (HTML and CSS). You often need to do this in order to include database values or other computed variables in the page output, in addition to any static HTML. You can include bigger chunks of HTML by referencing separate source files within your PHP source file, but often programmers simply start outputting content whenever they need to. This is quite a different approach to programming compared with interactive green-screen RPG programming, in which content (Display File DDS) is completely separated from logic (RPG workstation programs).
It doesn't take much to get used to this approach, and if you have already programmed in one of the other languages mentioned above, you'll be completely familiar with this notion. However, one of the drawbacks to this programming style is that it can make it difficult for you, or other developers, to read the programming logic because it is often intertwined with the presentation markup. Also, it can result in poorly designed and structured code that is ad hoc in nature.
This is both the blessing and the curse of PHP; it's extremely easy to start writing in it, but it's also easy to write bad code. For this reason, it's a good idea to invest time up front in developing programming protocols for developers to abide by that result in well-structured and organized code. For instance, one should consider encapsulating common routines, such as authentication and login routines, in separate source files.
The Open-Source Community
Because PHP is open source, there is a vast array of resources available on the Web for helping you learn PHP, write applications, or download open-source applications already written. For instance, a simple Google search for "PHP examples" yields 71,800 hits. The Web site sourceforge.net has numerous open-source PHP applications (most are free) that you can download and install. In a recent article I mentioned SugarCRM as an example of a full-blown customer relationship management application. This is available in both free and fee-based editions and is comparable in functionality to Microsoft Dynamics CRM-for much less money. Other prominent applications written in PHP include wiki software, used to run sites such as Wikipedia.org.
I mentioned earlier that the geeky origins of PHP are both its strength and weakness. It's a strength because the open-source community is constantly contributing to the PHP code base. Currently, over 5,000 functions are shipped as part of the standard PHP installation, and many plug-ins are available from open-source contributors. The downside to this, though, is the lack of a central profit-driven controlling body for managing code changes and assuring quality.
Most board members on open-source projects are volunteers who also have "day jobs," so there is a potential for mayhem in managing code releases. This is characteristic of open-source versus commercial software organizations and is a potential issue even with other open-source projects such as Apache. With PHP, this is mitigated somewhat by the presence of Zend, which is a for-profit company that was formed out of the open-source community and still has strong ties to it.
Getting Started with PHP on the System i
Zend has a Web page with information about Zend Core for i5/OS. (You need to be at V5R3 or V5R4 in order to use the Zend Core.) This is the engine that plugs into the Apache Web server to make your PHP scripts actually run. On this page, there is a link to the User Guide, a 102-page PDF document written by Zend (not IBM) that explains how to install it and documents the various System i-specific functions that Zend has provided to support the i5/OS's unique programming environment. For example, Zend has created functions for calling existing programs. This allows you to leverage your existing code base. For instance, you might have a complex pricing routine written in RPG. You can call this directly from PHP, which gives you the best of both worlds. Zend has also provided functions to access the native database on the System i, so RPG programmers can use functions similar to those used in RPG for accessing data. <?php print "Hello World!"; ?>
Once you've installed the Zend Core, you can start writing a test script. For example, the typical "Hello World" code might look like this:
You can save this as a text file with a .php extension to a directory on your IFS, say as "helloworld.php." When you install the Zend Core, the install process creates an initial Apache Web server configuration to support PHP. This will have a line that maps a URL to the directory path for this script. For example, suppose this line is in your config file:
If you store helloworld.php in the htdocs directory, you can run it at this URL:
(192.168.0.128 is just an example IP)
Generally, you might want something a bit more robust than this, with HTML tags to construct a complete page, but at least you can use this to test that your install works.
What PHP Is Not
PHP is not a development tool. However, many development tools, or IDEs, make it possible to write PHP code. The table below lists some examples.
|Development Tools |
|Enterprise-wide commercial offerings ||Zend Studio Professional, |
NuSphere's PhpED, Komodo IDE
|Simple commercial offerings ||Zend Studio Standard, PHPEdit, PHP Designer |
|Open source ||Eclipse, Maguma Studio |
|Free software ||HTML-Kit |
|HTML editors ||Macromedia Dreamweaver, Microsoft Expression Web |
|Simple text editors ||Textpad, Notepad |
Notice that I listed Notepad. Since PHP is written in simple text files, a developer can use Notepad to write PHP. However, all of the IDEs shown also include integrated FTP clients, which are necessary for uploading local files to the Web server. On the System i, you could save your files locally and then copy them to the IFS as a mapped Windows directory, but it's probably easier (and faster) to use the FTP facilities built into these tools.
So Come Join the Party
Now that you know the basics of PHP and how to get started, I encourage you to take a serious look at PHP. IBM and Zend have invested heavily in delivering PHP to the System i. I believe this will breathe new life into the platform, resulting in its becoming less proprietary. I also believe that programmers will enjoy programming in PHP and that many real-world business applications will be built with it. So come and join the PHP party!
Duncan Kenzie is President and CTO of BCD Technical Support, the development and support group for WebSmart, a popular iSeries Web development tool, and Nexus, a portal product specifically designed for System i, iSeries, and AS/400 servers. Duncan has 30 years of experience on the midrange systems platform creating software for both green-screen and native Web environments.