MC Press Online

Monday, Feb 27th

Last updateWed, 22 Feb 2017 3pm

You are here: Home ARTICLES Programming Web Languages Zend Brings PHP to IBM's i5/OS

Programming / Web Languages

Zend Brings PHP to IBM's i5/OS

SUPPORT MC PRESS - VISIT OUR SPONSORS

NEW BOOK!

IBM i Security Administration and Compliance


ORDER YOUR COPY

*******************

Click for this Month's

Bookstore Special Deals

PHP, the popular cross-platform Web development tool, shows great versatility. It offers power to the pro and simplicity to the novice. It runs on many hardware and software platforms, including Windows, Mac, UNIX, and System i. PHP offers other benefits as well:

  • Requires no licensing fees
  • Runs many blogs and content management systems
  • Can connect disparate systems with technologies such as SOAP
  • Is endorsed by IBM

With DB2 support, powerful extensions and commands, and an architecture built for the web, PHP brings modern functionality to System i, simplifying tedious tasks. I recently worked with an HTML "textarea" (large text box) and had to split the text into chunks of a maximum size, observing word breaks. A mundane, time-consuming programming job? No—with PHP's wordwrap function, I needed only one line of code.

Zend ("The PHP Company"), which coordinates PHP's open-source development process, provides software and services that help companies use PHP effectively. Zend and IBM have cooperated since 2004 to offer PHP-oriented products for IBM's servers and databases, especially DB2.

Programmers of All Levels

Even people without programming experience can use PHP. According to Michael Pinette, Zend's vice president of business development, an early Zend customer was a non-programmer psychiatrist who used PHP to provide online access to mental-health topics, reference material, and social-networking portals for specific disorders. While such newcomers can use PHP, the language has enough advanced features to satisfy experts who wish to write sophisticated object-oriented applications.

Zend's Added Value for System i

Zend is a great match for System i because it brings the priorities of the System i community—stability, trust, safety, easy administration—to PHP. For IBM, Zend provides reliable PHP distributions and value-added components. According to Andi Gutmans, Zend's co-founder and vice president of technology, the company performs rigorous testing on PHP, selecting the most stable, best-performing versions for release in Zend Core. The first generally available (GA) release of Zend Core will include version 5.1.4 of PHP, says Gutmans. Gutmans estimates a six-month lag between the appearance of an open-source version of PHP and its Core release, "so it's stable and bulletproof, and customers won't hit walls."

Gutmans says Zend intends to port all its products to System i, treating the platform's users as first-class citizens, with the full solutions that other platforms enjoy.

Support

Zend users needing technical support can go to the Zend Support Center and obtain the first "support ticket"—continued help until a single problem is resolved—free. Subsequently, paid support is available at several levels, including 24x7 phone support. If a problem needs a collaborative resolution, Zend will work with IBM's engineers to solve it. In addition, free assistance may be requested at the Zend forums, with the usual delays and uncertainties inherent at volunteer help sites.

System Requirements

Zend Core requires i5/OS V5R4 or higher. Although IBM may eventually overcome technical hurdles to allow V5R3 support, this development is far from certain. System i users who want to try Zend in the near future would be wise to upgrade to V5R4, installing all relevant PTFs, especially the latest HTTP Server (Apache) PTF group.

Besides V5R4, users must install the following licensed programs:

Zend Core Required Licensed Programs
Description
Product Option
Licensed Program
Portable Application Solutions Environment (PASE)
33
5722SS1
Qshell
30
5722SS1
System Openness Includes
13
5722SS1
Digital Certificate Manager
34
5722SS1
IBM Portable Utilities for i5/OS
*base
5733SC1
OpenSSH, OpenSST, zlib
1
5733SC1

How to Install Zend Core

After verifying the system requirements above, download Zend Core and Studio from Zend Network i5/OS page. Register as a Zend Network member to obtain access to Zend Core and Studio, discussion forums, support, and automatic software updates. When asked to select a "channel," click the link labeled "Zend Core," leading to a download page. From there, save the zip file to your hard drive. Extract the Zend Core files using an unzip tool such as ZipGenius. The extracted files include a save file, release notes, and a user guide.

For installation details, consult the release notes and user guide. Here are some additional tips (as of Version 1.3.1, the latest available at press time):

  • One "prerequisite" can be ignored. You do not need licensed program 5722ac3, Crypto Access Provider 128 bit. The functionality of this program has been absorbed into other programs.
  • The installation uses IFS directory /usr/local. Create /usr/local before installing Zend Core. Make sure it is a true directory, not a symbolic link to another directory. (Confirm with the command WRKLNK '/USR/LOCAL' and then option 8, "attributes.")
  • Sign on as QSECOFR for the installation process.

If any Web errors should occur, check for error messages in the following log files: /usr/local/Zend/apache2/logs/error_log .* or /usr/local/Zend/core/logs/php_error_log

Once you have installed Zend Core, the administration Web site will be available to you. The URL (by default) is http://www.myserver.com:8000/zendcore (myserver.com is any domain name assigned to your System i). Place your own PHP scripts in /www/zendcore/htdocs. They will run from http://www.myserver.com:89. Figures 1 and 2 show the Control Center and PHP Configuration pages.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V400.png

Figure 1: Zend Core for i5/OS Control Center shows the status of PHP and the Web server. (Click images to enlarge.)

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V401.png

Figure 2: The Web-based PHP Configuration page is easier to read than old-fashioned PHP.INI files.

Installing Zend Studio

Download the appropriate version for you (Windows, Mac, or Linux) from the same page from which you downloaded Zend Core. The Windows version that I tried was a self-extracting executable file that installed easily.

Menus in 5250 Mode

Most of Zend Core's options are available on the Web-based administration interface. Some actions, though, can be run from a 5250 screen.

Main menu (shown in Figure 3): GO ZENDCORE/ZCMENU

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V402.png

Figure 3: The Zend Core 5250-based setup tool offers access to the Apache menu and a few other selections.

For direct access to the Apache menu: GO ZENDCORE/ZCAMENU

Administrators can control Zend Core's Apache server programmatically (for example, upon IPL) with these lines:
Start: CALL ZENDCORE/ZCCAPCS001
Stop: CALL ZENDCORE/ZCCAPCE001
Restart: CALL ZENDCORE/ZCCAPCR001

Power from Extensions

Extensions contain targeted bits of functionality. When compiled into PHP, they act as seamless parts of the language. Although anyone may write an extension and compile it into PHP, Zend has selected the best for inclusion in Zend Core, Gutmans says. Gutmans and his colleagues have included the most widely used extensions that meet their standards of quality, including, for example, ibm_db2 for optimized db2 access and gd for creating graphics dynamically.

Figure 4 shows the Extension Configuration page.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V403.png

Figure 4: Extension Configuration allows extensions to be activated and configured.

At press time, Zend Core for i5/OS included the following extensions: bcmath, bz2, calendar, ctype, curl, db2, dom, exif, ftp, gd, tidy, gmp, ibm_db2, iconv, imap, ldap, libxml, mbstring, mcrypt, mhash, mysql, mysqli, openssl, pcntl, pcre, posix, session, shmop, simplexml, soap, sockets, spl, sqlite, standard, sysvmsg, sysvse, sysvshm, tokenizer, xml, xmlreader, xsl, zip, zlib, ming, and wddx.

Alternative to mail()

The first GA release of Zend Core will not support PHP's mail() command. System i does not have the "sendmail" program that mail() requires. Applications needing to send or receive email must use an alternative, such as the free PHPMailer class. Newcomers can get started quickly with the PHPMailer Tutorial.

Integration with Traditional i5/OS Objects

Generic, open-source distributions of PHP do not handle System i's special object types such as data areas, data queues, and message queues. Such distributions have no straightforward method to call i5/OS commands and programs written in RPG, CL, and COBOL. Zend Core is gradually filling this gap in the following ways:

  • Beta V2 (early July 2006) will have a "bridge" to RPG, CL, and other i5/OS native program objects.
  • GA (late July) will have further bridges to data queues and message queues.
  • Future releases may offer integration with other objects, such as data areas.

Database Access

Zend Core's PHP distribution has several extensions that enable users to connect to databases on System i and other platforms, as shown in the following table.

Database Extensions in Zend Core for i5/OS
Extension
Description
Notes
db2
DB2 unified ODBC driver
The db2 extension provides a native db2 driver, accessed with the generic ODBC interface.
ibm_db2 (recommended)
Native, optimized extension for DB2
IBM's DB2 and System i engineers collaborated to make a high-quality, well-performing extension. Zend further tested it for reliability.
PDO (not available)
PHP Data Objects
Not yet mature and stable enough for inclusion in Zend Core, PDO is an object-oriented, portable, generic interface to database drivers.
mysql, mysqli
MySQL database access
Although PHP works well with the MySQL extensions, Zend Core does not include MySQL server software. Users who want MySQL should download it using instructions such as these.


One easy way to get started with the ibm_db2 extension is to go to an example from Zend's "Developer Zone," copy it, and adapt it. The SOAP example later in this article also uses ibm_db2.

Zend Studio Is a Bonus That Speeds Development

Zend Studio Professional is a graphical development environment intended to speed development and improve code quality. System i customers are getting this excellent package free while others pay $240 list price.

Available for Windows, Mac, and UNIX clients, Studio is a dazzling productivity booster. Anyone still using a simple text editor is urged to try Studio.

Consider the following examples from the Zend Studio feature list. The 5.2.0 beta version was used.

Interactive debugger (Figure 5): Studio has a sophisticated debugger. While code runs, the debugger shows the function's output (text and HTML format), values of variables, the call stack, and more.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V404.png

Figure 5: In the debug demo, the Debug Output pane shows the accumulation of HTML or text source as code runs.

Coding errors are uncovered by the "real time" syntax checker (Figure 6):

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V405.png

Figure 6: The syntax checker noticed that a parenthesis was missing.

The code analyzer (Figure 7) produces a detailed error log.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V406.png

Figure 7: The code analyzer found an unused variable, indicating a potential error.

SQL Support can work with structures and data of many database types (Figure 8).

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V407.png

Figure 8: Studio's SQL facility shows MySQL data from a Mambo content management system.

Version and Source Code Control

Zend Studio includes built-in clients for the popular Concurrent Versions System (CVS) and Subversion (SVN) version control systems. Administrators can download and install the open-source server portions from the Web. SVN, according to Gutmans, is superior to CVS and is adequate for teams of up to 10 developers.

Large teams might prefer a more robust version control system. Under discussion, Gutmans says, is the possibility that Zend will work with Eclipse and enterprise-grade version control such as IBM Rational ClearCase for more complex development environments.

Zend Studio Simplifies SOAP

Simple Object Access Protocol (SOAP) is an XML-based format that applications can use for exchanging data, primarily via HTTP. When two applications communicate, the data provider is called the "SOAP server." The data consumer is called the "SOAP client." How does the client know what services are offered by the server? A Web Services Description Language (WSDL) file defines the server's input and output. Zend Studio, with its ability to generate WSDL files, greatly speeds the preparation of SOAP services.

When I ran a quick personal test of PHP's SOAP extension and Zend Server's WSDL generator, everything worked easily. The example below, adapted from a sample by Zend's Shahar Evron, includes a server script (fruitserver.php) and a client script (fruitclient.php).

Step 1: Create table with data to retrieve.

From STRSQL on a 5250 terminal, I created a table and gave it two records of test data:

CREATE TABLE FRUIT/APPLES (COLOR CHARACTER (10 ) NOT NULL WITH DEFAULT, NAME CHARACTER (20 ) NOT NULL WITH DEFAULT)
INSERT INTO fruit/apples (color, name) VALUES('red', 'Red Delicious')
INSERT INTO fruit/apples (color, name) VALUES('green', 'Granny Smith') )

Step 2: Create the server code, fruitserver.php (Figure 9).

The "at" signs (@) are part of phpDocumentor format, which helps generate WSDL markup. Note that fruitserver.php retrieves System i data using the ibm_db2 extension.


/**
 * Fruitserver.php
 * A sample SOAP server using a WSDL file generated with Zend Studio
 */

/**
 * This class describes a fruit-fact provider: It provides information about common fruits. 

It gets the information from an IBM System i DB2 database.
 * 
 * Objects of this class be used internally in your application
 * as well as exposed as a SOAP service.
 * 
 */
class fruitfacts
{
      /**
       * Return the apple's name based on color.
       *
       * @param string $color
       * @return string
       */
      public function appleNameFromColor($color)
      {
            $applename = ""; // intialize

            // connect to System i DB2 database using default database 

name, user, password
            $conn=db2_connect("","","");
            if (! $conn) {
               return db2_conn_errormsg();
                  } else {
   
            // query our System i DB2 database
            $sql="select name from fruit.apples where color=? ";
            $stmt = db2_prepare($conn, $sql);
            $result = db2_execute($stmt, array($color));

            $row = db2_fetch_both($stmt);
            if ($row) {
               $applename = $row['NAME'];
               }
            db2_close($conn);
            } // the else of connection OK

            // color not found
            if (! $applename) {
               $applename = "unknown apple";
            }
            return $applename;
 
      }

}

// Set up the SOAP server, specifying wsdl file
$server = new SoapServer('http://www.myserver.com:89/soaptest/fruitfacts.wsdl');
$server->setClass('fruitfacts');

// Handle SOAP requests
$server->handle();

Figure 9: Fruitserver.php contains one class, one function, and a few SOAP commands.

Step 3: Create the client code, fruitclient.php (Figure 10).


           :
          
          
          
           :
          
          
          
           :
          
          

      


/**
 * Fruitclient.php
 * This is a sample script that uses the Fruitserver SOAP service. 
 * 
 * It demonstrates how to set up SOAP clients using WSDL files.
 */

// Try to set up the SOAP client and get the data
try {
      // WSDL files can be read directly from the web!
      $client = new 

SoapClient('http://www.myserver.com:89/soaptest/fruitfacts.wsdl');

      $color = array("red","green","purple");
      $fruitname = array(null,null,null);

      // pass in three colors, get three fruit names from the server
      $fruitname[0] = $client->appleNameFromColor($color[0]);
      $fruitname[1] = $client->appleNameFromColor($color[1]);
      $fruitname[2] = $client->appleNameFromColor($color[2]);

} catch (SoapFault $fault) {
      $errorMsg = "SOAP error {$fault->faultcode}: {$fault->faultstring}";
}
?>


  SOAP Example




     

 padding: 2px; font-family: fixed; font-size: 9pt;">
            
      



      SOAP example: get apple name by color 
     
            This SOAP client passes a color to a remote SOAP server. 

The server returns a variety of apple matching the color. 
     
     
      Apple colors and varieties:
     

          



Figure 10: Fruitclient.php uses a few SOAP commands (near the top) to get data from fruitserver.php.

Step 4: Run the WSDL Generator Wizard from the Tools menu, as shown in Figures 11 to 17.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V408.png

Figure 11: The WSDL Generator Wizard creates a configuration.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V409.png

Figure 12: Select PHP files to analyze.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V410.png

Figure 13: Point the Wizard to fruitserver.php, where our service function resides.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V411.png

Figure 14: The WSDL generator reports its intention before creating the WSDL.

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V412.png

Figure 15: The WSDL file was created.

I was glad I didn't have to create fruitfacts.wsdl by hand (Figure 16).





xmlns:typens="urn:testsoap" 

xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 

xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 

xmlns="http://schemas.xmlsoap.org/wsdl/">
     
           
     
     
           
     
     
           
                  This class describes a fruit-fact provider: It provides 

information about common fruits.
           
           
                 
                        Return the apple's name based on color.
                 
                 
                 
           
     
     

type="typens:fruitfactsPortType">
           

transport="http://schemas.xmlsoap.org/soap/http"/>
           
                 
                 
                       

use="encoded" 

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                 
                 
                       

use="encoded" 

encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
                 
            
       
       
             

binding="typens:fruitfactsBinding">
                 

location="http://www.myserver.com:89/soaptest/fruitserver.php"/>
           
     

Figure 16: Fruitfacts.wsdl defines the services offered by fruitserver.php.

Now we run our SOAP client in a browser. It accesses WSDL and the SOAP server, retrieving our apple varieties (Figure 17).

http://www.mcpressonline.com/articles/images/2002/Seiden_Alan_iAppDesigner_PHP_REVISED_7-4-06_V413.png

Figure 17: The client, the server, and the WSDL file work together.

Probable Schedule of Zend Releases for i5/OS

According to Andi Gutmans and Michael Pinette, Zend's releases for System i will be as follows:

Zend's Releases for System i
When
Product
Version
early July 2006
Zend Core, Zend Studio
Version 2 beta
end of July 2006
Zend Core, Zend Studio using PHP V5.1.4. Free for System i users.
GA
3rd quarter 2006
Zend Guard to encode PHP. Good for security and retaining intellectual property. Useful for independent software vendors (ISVs). Cost to be announced.
GA
late August 2006
Zend Platform, Zend's flagship product for the enterprise, with acceleration, caching, performance monitoring, and Java Bridge. Cost to be announced.
GA
end of 2006
Zend Framework, which further speeds application development with standard architecture.
still in discussion
then...?
Watch the Zend for i5/OS forums for news

Figure 19: Zend is steadily providing all its products to IBM System i.

A New Approach to System i Web Development

In porting PHP to System i, IBM and Zend have given the community a powerful, low-risk approach to Web development. Developers who use PHP strengthen the platform while mastering technology that can run almost anywhere. PHP re-energizes System i with advanced capabilities for the Web that are easy to use. The advantages of System i—reliability, virtualization, scalability—remain.

Resources

Zend for i5/OS
Zend for i5/OS Discussion Forums (Core and Studio at this time)
Zend Forums for all platforms and products

•"IBM DB2 Universal Database, Cloudscape, and Apache Derby" by Dan Scott (PDF)

Zend Developer Zone
Zend Framework (currently in preview but reportedly stable and worth trying)

• Charts and Graphs in PHP: PHP/SWF Charts, JpGraph, PHP SOAP Extension

Alan Seiden is a consultant and developer at a northern New Jersey IT firm, where he enjoys his role as a creative software catalyst for clients. Alan is vice president of the New York City Usability Professionals Association. Email: This email address is being protected from spambots. You need JavaScript enabled to view it..

Alan Seiden

 

Alan Seiden, an authority on PHP development with IBM i, helps companies achieve best practices and top performance when combining PHP, Zend Framework, IBM i, RPG, and DB2. An award-winning speaker, Alan is project manager of Zend's open-source PHP Toolkit for IBM i. Alan Seiden Consulting, Ho-Ho-Kus, N.J.: http://www.alanseiden.com | alan@alanseiden.com | @alanseiden

BLOG COMMENTS POWERED BY DISQUS