23
Mon, Dec
1 New Articles

PHP: What Can You Do with It on Your System i?

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

PHP takes you where RPG can't: into a world of heterogeneous operating systems running the same language.

 

PHP is a highly productive programming language for developing Web applications. As I mentioned in an article in Showcase magazine ("PHP: A Party Waiting for a Few Good Developers"), PHP has been around since 1995 on other platforms and has gone through as many transformations as RPG has during that time. In this article, I'll discuss what PHP can do for you and why you should consider using it.

 

PHP is open-source software. Although a private company, Zend, provided the version of PHP for IBM that runs on the System i, the base Zend parser is still open source, with developers around the world continuing to contribute to its code base. (Source: http://en.wikipedia.org/wiki/Zend_Engine.)

PHP on System i

PHP can (and does) run on many operating systems, including Linux, UNIX, and BSD-based OS's, besides Windows and System i. At this point, System i is still comparatively a niche market for PHP, as it was only recently made available in an easily installable form with special extensions to support the native i5/OS database DB2.

 

On the System i, PHP runs as an Apache extension called Zend Core. Apache is the most widely used non-proprietary Web server. A customized version runs on the System i. It is also open-source code and runs on all the other platforms I mentioned earlier, with a common code base for those. You can run PHP as a CGI or with the  ISAPI module in Microsoft's Web server, IIS, but there are weaknesses with this approach as described on this page.

When Zend ported PHP to the System i, they took advantage of the PASE environment, which lets you run a UNIX partition directly in i5/OS. The Apache server actually acts as a proxy server when it encounters an HTTP request that is intended to run a PHP script and then farms it off to a PASE environment job, all transparently to both the end-user and the system administrator. This was a brilliant idea on Zend's part because it meant they didn't have to rewrite the entire code base. Instead, PHP essentially runs like it would on any UNIX box. In order to take advantage of i5/OS-specific features, though, Zend needed to write functions that cross the boundaries between the UNIX world and the native i5/OS world. These include functions for accessing the native DB2 database, calling i5/OS programs, and working with i5/OS objects such as data areas, data queues, user spaces, and spool files.

 

So, what can you do with PHP on your System i? 

•·        Create new Web applications that use the native DB2 database

•·        Create new Web applications that use a MySQL database installed on the System i

•·        Interface to legacy applications by directly calling ILE programs or modules

 

What can't you do?

•·        Replace RPG totally with PHP. For example, you'll still need RPG for batch programs and for report programs that generate spool files (if you need standard text-only reports versus HTML reports).

•·        Replace CL totally with PHP. CL is highly specialized for running system commands. However, the i5 PHP API toolkit does include a function that lets you embed calls to CL commands directly in your PHP script. This feature allows you to run many, but not all, CL commands. You cannot run those commands that require the execution environment to be a compiled CL program, for example. 

•·        Web-face existing interactive RPG programs. You'll need some other tool, such as HATS or third-party vendor tools, if you want to re-face and run green-screen programs in a browser.

Creating Web Apps with PHP

So the primary role of PHP is to create "native" Web applications, those that use the HTTP protocol in a typical way, which generally involves having the browser directly communicate with the Apache Web server, which in turn draws on the resources of the underlying i5/OS operating system to perform data manipulation and computations.

 

When you use PHP in conjunction with the latest Web 2.0 technologies, you can create Web applications that are highly responsive to users and provide sophisticated interfaces and immediate, event-driven feedback. These technologies are now commonly available and mostly open source. They include JavaScript libraries, plug-ins, and frameworks, in addition to the standard client-side Web programming facilities such as HTML and CSS.

 

We are starting to see some powerful Web 2.0 interfaces in common use now on public, commercial sites. For example, Flickr, the online photo management site, has an application for organizing your photos into sets simply by dragging and dropping thumbnails of the photos on a work area. As you release the mouse to place a photo in the set, a back-end server process kicks in that updates your Flickr database to record the new location of the photo persistently. Another example is Facebook, the popular social networking site. There, you'll see messages or prompts for more information pop up in your browser when you confirm your response to a "friend request." Rather than reload the entire page, Facebook's server just sends a "page partial" and updates the back-end Facebook database.  

 

However, none of the Web 2.0 sites actually require that the back-end programming language be PHP. You could use any Web language to interact with the client-side technologies that make this cool stuff happen. So why would you choose PHP for your server-side language? You could choose RPG or any number of third-party tools that use RPG as their basis. However, PHP has some significant advantages over RPG for Web development.

Functions, Functions, and More Functions

PHP has thousands of functions to support Web application development. For example, there's a set of over 50 PDF writer functions that enable you to create sophisticated PDF documents programmatically with PHP. These functions are documented on the PHP.net Web site. The list of function categories alone must contain over 200 items (I didn't count them all). Just about any Web programming need you can conceive of is covered by these functions. For example, in the calendar category there is a function called easter_date, which, you guessed it, returns what day Easter falls on in any given year. If you've ever written a calendar application and had to try to figure that one out, you'll recognize the depth of research that has gone into building all these PHP functions. In case you are interested, here's the formula to compute Easter.

 

You might find the LDAP set of functions more relevant to your application development needs. LDAP lets you have a single location (a "directory") for storing login information  for signing on to a network of heterogeneous systems, which lets you approximate the nirvana of single sign-on. Your users will still have to log in to any sites you secure with LDAP via the browser, even if they use the same directory to log in to Windows or their System i sessions, but at least there's a central place where all user profile information is stored.

PHP: An Open-Source Language for Web Development

PHP is relatively easy to write, and it was designed specifically for Web development. It's a loosely typed language, so it's quite forgiving in how you reference variables. It's also a procedural, imperative language, meaning it uses semantic ideas similar in concept to RPG. For example, RPG has subprocedures and PHP has functions. Of course, PHP is a free-format language, and it uses syntactical features similar to most common languages such as C, C++, C#, Java, JavaScript, Visual Basic, free-format RPG, etc. You can also write PHP as object-oriented code, so if you are used to writing in Java, the transition to PHP should be fairly easy. PHP lets you interleave HTML and server-side code, like many of the Web development languages do. This can be a challenging concept for green-screen RPG programmers to get their heads around initially, as they are used to coding the UI (display file DDS) independently of the logic (RPG code), while the most common style of programming PHP is to simply break into the logic at any point you need to and start writing HTML. PHP also supports including variables in any output HTML simply by including the variable name inside the content.

 

Because PHP is open source, you also benefit from a huge reserve of code that you can mine. Many PHP Web sites provide complete working PHP applications you can download and use for your own needs. Sometimes, you may use these simply as learning tools; other times, you may actually want to incorporate the code. Check the licensing terms of the code to make sure you are not violating copyright before you choose the latter option, although generally you'll find most PHP code is liberally licensed. One caveat, though: There's no guarantee the code you are looking at is well-written, let alone works correctly. You'll probably come across a lot of mediocre code, as well as nuggets of real value.

 

PHP is stored in ASCII text files. While RPG programmers are likely to use SEU or WDSc to edit source, you can write PHP in any PC-based text editor, such as Notepad or SlickEdit, or any PHP-specific editor, such as Zend Studio or Eclipse with the PHP plug-in. You can also use third-party tools such as BCD's WebSmart for PHP to generate PHP from templates and edit it. This tool is written specifically to take advantage of the System i platform. 

 

With PHP, you store the source files on the IFS and map the appropriate IFS directory to a URL in your Web server configuration so that users can run the scripts from their browsers. When the scripts run, they deliver the Web content (usually an HTML page) to the browser. It's important to realize that even though the PHP script source file is invoked directly during this process, the end user never sees this source, just the results of it's execution, which is the delivered page.

PHP is primarily an interpretive language. Critics of PHP often claim that this reduces its commercial appeal because of potential scalability issues. However, many large Web sites run PHP successfully, with considerable amounts of traffic. In addition, Zend has a product (Zend Platform) that mitigates this issue by providing load balancing, source-code caching, and on-the-fly code optimization.

 

People often wonder if PHP is really suitable for business applications. That may be because many early visible implementations of PHP were for apps such as bulletin boards, calendars, or public portals. These don't necessarily resonate with System i developers. However, PHP can be used for mission-critical, commercial applications too. A good example of a commercial application is SugarCRM, which is a Customer Relationship Management (CRM) product. It is suitable for large organizations and uses MySQL as the back-end database to store information about customers, calls, salespeople, etc. SugarCRM is open source (but not necessarily free) and has been ported to the System i. Of course, you are not limited to creating CRM applications with PHP. Because it can work directly with the native i5/OS DB2 database, you can build all the same types of applications you'd want to build as 5250 interactive, but with way more functionality. These include order entry, accounting, payroll, sales analysis, utility billing, online shopping carts, enterprise portals, hospital patient tracking, etc. Really, anything you can think of that's a typical business problem that needs solving you can write in PHP.

 

To get started with PHP, consider following this plan:

•·        Select a small, low-risk, well-defined development project.

•·        Take a couple of PHP classes.

•·        Learn HTML and CSS (in a later project, you'll want to learn JavaScript also).

•·        Read Zend's Zend Core User Guide for i5/OS. This explains the APIs that let you use System i-specific functionality in PHP.

•·        Install Zend Core on your System i (this is not complicated).

•·        Download some of the mountains of available source code.

•·        Try one of the PHP editors or development tools on a trial basis.

•·        Start writing code.

•·        Deliver and then watch the smiles on your users' faces!

 

One final advantage of PHP is that it is supported across multiple platforms. That means the gene pool for developers is much larger than the RPG gene pool. Most Computer Science students have at least some familiarity with PHP these days and are much more likely to want to learn PHP than RPG. This gives you the option down the road to easily share the strengths of other platforms such as Linux or UNIX without having to learn new technologies, yet while still leveraging the strengths of the System i. PHP succeeds where Java has failed: It's simple to learn, lightweight (does not require lots of system resources), and easy to install and run. PHP takes you where RPG can't: into a world of heterogeneous operating systems running the same language so you can leverage your programming knowledge and have skills that will be applicable for many years.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: