10 Cool PHP Things You Can Run on Your System i

Article ID: 21129

PHP is one of the most popular web development tools. With Zend Core for i5/OS (zend.com/en/products/core), the System i community has access to an incredibly diverse body of programming tools, code packages, and even full-fledged applications.

In this article, I focus on 10 "cool" open-source PHP components that are easy to install, offer business value and, in many cases, are highly graphical.

A note about file formats: Downloads are compressed as zip files or tar.gz. To extract tar.gz files from within Windows, I recommend using ZipGenius (zipgenius.it), a free zip utility.

1. PHP/SWF Charts

PHP/SWF Charts (maani.us/charts) creates attractive, colorful, animated charts and graphs on the web. Your scripts provide the data, which can come from your DB2 database or any other source. The charts are built in Flash, the popular cross-browser technology. (Flash Player 6 or later must be installed in your visitors' browsers. You can download Flash for free at macromedia.com/go/getflashplayer.)

The basic version of PHP/SWF Charts is free. For the registered version, which includes technical support and the ability to link charts to other web content and embed charts in other Flash documents, the author charges a modest license fee. Registered users can click charts to drill down for details. To install the program, download and extract charts.zip. Copy the contents (charts.swf, charts.php, and charts_library) into a web server directory such as /www/zendcore/charts. To see samples of the many available charts — line, pie, bar, mixed, and more — go to the "gallery" section of the PHP/SWF Charts website at maani.us/charts/index.php?menu=Gallery. Code samples are available at maani.us/charts/index.php?menu=Reference.

Using the code in Figure 1, I created an example chart (Figure 2). Although not apparent from the screen shot, script 3dpie.php generates a 3-D animated, spinning pie chart from data I provided. Showchart.php uses the InsertChart function to output the chart. On my server, I ran the script with a URL similar to http://example.com:89/charts/showchart.php.

2. PHP Interactive

For developers, PHP Interactive (hping.org/phpinteractive) is a simple PHP program that provides a convenient, web-based way to test PHP ideas. You don't need to create standalone PHP script files every time you want to try something new. Paste your PHP code into PHP Interactive and try it there.

When you click "update," the results of your script appear below (Figure 3). You can choose between raw or HTML (browser-style) views. You can also add multiple tabs (each holding a script), name the tabs, and delete tabs. PHP Interactive remembers your scripts from session to session.

To aid development, the program provides a search box to look up PHP function definitions, leading to the appropriate manual page. To install the program, download and extract contents of phpinteractive-0.2.tar.gz. Inside the phpinteractive folder, create a subdirectory called /scripts. (The application needs this scripts folder for storing the scripts you create.) Now copy the phpinteractive folder under /www/zendcore, making /www/zendcore/phpinteractive/. Run phpinteractive on your System i at a URL such as http://example.com:89/phpinteractive.

3. Dial Gauge

Dial Gauge (phpclasses.org/browse/package/4080.html — free membership required) provides a visual progress indicator that resembles a car's speedometer. The developer needs to supply only a low and high range and the number to display. Such a display could be useful in executive dashboard systems.

To install the package, download and extract the zip file. Copy the files to a folder such as /www/zendcore/dialgauge. Within Zend Core, you will need to enable the "gd" graphics library, a popular toolkit for the dynamic creation of images. You can do this by tapping Zend Core's administration pages (Configuration/Extensions) and then restarting Zend Core. You can run the example script on your server at a URL such as http://example.com:89/dialgauge/example.php. Figure 4 shows an example of a gauge.

4. TailFile Class

When Unix professionals want to see the latest entries in a large log file, they use the "tail" command. With the TailFile class (phpclasses.org/browse/package/499.html — free registration required), you can control "tail" functionality from PHP. I show how to use it to detect any new errors that appear in the PHP error log.

To install the program, download and extract the contents of the zip file. Copy the contents, tail-example.php and tailfile.phpc, to a directory such as /www/zendcore/tailfile. I've modifiedtail-example.php (Figure 5) so that it works with Zend Core for i5/OS. I called my version check_php_log.php. It checks the PHP error log for new errors, something I often want to do.

My script is meant to run in the QShell terminal environment rather than in a browser. Why? A browser will not let a web page run perpetually. It will time out unless JavaScript redirects the address periodically. QShell has no such restrictions. It lets a PHP script run a continuous loop. Here you see PHP's power for general-purpose shell scripting.

I launched QShell and my script with the following statement:

qsh 
/www/zendcore/htdocs/tailfile/check_php_log.php

Press F3 to exit. Figure 6 shows the recent messages that my script found.

5. Sparkline PHP Graphing Library

According to Edward Tufte, an expert on analytical design, sparklines are "intense, simple, word-sized graphics." Thanks to the package at sparkline.org, developers can embed sparklines in otherwise dry reports or web pages.

To install the library, download and unzip the contents of the zip file into a folder such as /www/zendcore/htdocs/sparkline. Within Zend Core, you need to enable the "gd" graphics library extension. You can do this by accessing Zend Core's administration pages (Configuration/Extensions) and then restarting Zend Core. Several sample scripts are included. I ran one that charts the performance of IBM stock using dynamic data from Yahoo Finance. The URL with parameters was something such as http://example.com:89/sparkline/samples/stock_chart2.php?s=ibm&y=5. Figure 7 shows the resulting sparkline.

6. Mantis/400

Mantis (mantis400.com) is a popular web-based help-desk and bug-tracking application. You'll never lose track of support issues again! Best of all, Mantis has run on good old DB2 since 2007, when I worked with consultants from IBM, Zend, Curbstone Corporation, and Mantis's project leader, Victor Boctor, to create Mantis/400, a DB2-enabled version.

When you run Mantis/400, its data is saved in ordinary DB2 files. Your traditional programming tools, such as RPG, can access these files.

Mantis includes the following features:

  • IT staff members and end users can report and comment on bugs and issues. (Figure 8 shows Mantis's own issue list.)
  • Users can upload supporting files (e.g., logs) to report their issues.
  • The system can automatically send e-mail to appropriate users when reports are updated.
  • Categories allow for easy searching of issues.
  • Change logs help build a methodical change-management process.
  • IT staff members can post product road maps and news.

To install the application, go to mantis400.com and request a free CD or download Mantis on the spot. You can install the product with the LODRUN command. Zend's proxy Apache server (ZENDCORE, running in QHTTPSVR) requires a configuration change so that Mantis will recognize your domain name. The file to change, by default, is /www/zendcore/conf/httpd.conf. The setting is ProxyPreserveHost On.

7. Grider

Grider ( phpclasses.org/browse/package/2538.html — free registration required) is a web-based editor for creating and editing HTML tables. With Grider, you can add and remove table cells as well as adjust the colspan and rowspan attributes of the cells. This feature makes it easy to design table layouts even when they have complex rowspan/colspan combinations, such as when a list has embedded headers and labels.

To install the editor, download and extract the contents of the zip file. Copy the contents to a folder such as /www/zendcore/grider in your web server. You'll be able to access the application through your browser with a URL such as http://example.com:89/grider/index.php.

Figure 9a shows a table layout, and Figure 9b displays the resulting HTML code. To change columns, colspans, rows, and rowspans, click the appropriate cell and then click [+] or [-]. When you click "HTML," Grider generates HTML that you can copy into your web pages.

8. Antispam

If your e-mail inbox is full of spam, could automated spam systems have harvested your address from your website? The Antispam package (phpclasses.org/browse/package/1088.html — free registration required) has a solution. Rather than embedding an e-mail link directly in your pages where the address can be harvested by spam bots, you can embed JavaScript that creates an obfuscated e-mail link. Users can see the address and can click it normally, but most automated systems cannot. (Note: Users must have JavaScript turned on in their browsers.)

Here's an excerpt of the example given by Antispam's author, Stanga Razvan:

$antispam = new AntiSpam; 
echo $antispam->email ( "cool@computergames.ro" ); 

It generates

<SCRIPT LANGUAGE="JavaScript"> document.
write('<a href="' + 'mailto:' + 
'cool' + '@' + 'computergames.ro' 
+ '">' + 'cool' + '@' 
+ 'computergames.ro' + '</a>'); </script>

If your link includes your name as well as your e-mail address, the name and address will be encrypted inside the JavaScript, making it even harder for robots to harvest.

To install Antispam, download the zip file and extract its contents to a folder such as /www/zendcore/antispam on your web server. You can access the application through your browser with a URL such as http://example.com:89/antispam/anti-spam.php.

9. Phoogle Maps

Phoogle Maps (systemsevendesigns.com/phoogle) let you use the Google Maps API to embed customized maps on your website. The maps look like the maps on Google's own site(maps.google.com). Users can zoom in and out and do everything they would normally do with a Google map. Figure 10 shows a simple example in which I map two addresses. Figure 11 shows the resulting map.

To install the maps, download the zip file and extract its contents to a folder such as /www.zendcore/phoogle on your web server. You'll be able to access the application through your browser with a URL such as http://example.com:89/phoogle. The Google Maps API service requires you to get your own free Google Map API key at code.google.com/apis/maps.

10. WordPress

WordPress (wordpress.org) is a feature-rich, free, open-source blogging package. Its active community works constantly to improve its quality and add features.

WordPress's installation process takes only minutes if you lay this groundwork:

  1. Make sure that MySql is installed and running. With newer versions of Zend Core, it should be.


  2. Enable the MySql extension in Zend Core. You can do this by tapping Zend Core's administration pages (Configuration/Extensions) and then restarting Zend Core.


  3. Create a WordPress database within MySql with a tool such as phpMyAdmin (phpmyadmin.net) or using the command line (dev.mysql.com/doc/refman/5.0/en/creating-database.html). You can name the database "wordpress," "blog," or a name more specific to the blog's purpose.


  4. Check that Zend's proxy Apache server (ZENDCORE, running in QHTTPSVR) contains the setting ProxyPreserveHost On. This setting lets WordPress receive the proxy server's domain name. Apache's configuration file, by default, is /www/zendcore/conf/httpd.conf.

To install Wordpress, download the zip file from wordpress.org and extract its contents to a folder such as /www/zendcore/wordpress on your web server. To launch the installation process, go to the appropriate URL, which will be similar to ftp://example.com:89/wordpress/. Follow the on-screen installation instructions. Let the installer create a configuration file (wp-config.php) for you. You will be prompted for the name of your MySql database, its user and password, the database host name (probably localhost), and a table prefix (wp_ should be fine).

After the installation is complete, you will be given a random password that you can use to sign on as admin. You can start blogging immediately by clicking Write a Post. Figure 12 shows WordPress's blogging page as I wrote my first posting on this system. Figure 13 shows the resulting page as the public would see it.

Cool Things Abound

PHP opens up a world of applications that are not only cool but also add business value to your organization. With relative ease, you can run great PHP applications on your trusty System i.

Alan Seiden enjoys leading collaborative projects, developing software, and troubleshooting clients’ perplexing problems. A member of New York PHP since 2004 and an early booster of PHP on the System i, Alan was profiled in the newsletter of the New York Software Industry Association (nysia.org/special_features/article.cfm?pid=383). Alan’s IT blog is at alanseiden.com. You can reach him at alan@alanseiden.com.

ProVIP Sponsors

ProVIP Sponsors