PHP on IBM i RPG Examples - MRMUGmrmug.org/archives/docs/November 2014 Presentation... · PHP on...

Preview:

Citation preview

© All rights reserved. Zend Technologies, Inc.

PHP on IBM i RPG Examples

Mike Pavlak

Solution Consultant

Mike.p@zend.com

© All rights reserved. Zend Technologies, Inc.

Agenda

•Open Source Toolkit

•RPG Program Calls

•Stored Procedures

•Q&A

2

© All rights reserved. Zend Technologies, Inc.

Zend Server 7 for IBM i

Key Features

Z-Ray (Like Firebug for PHP)

Server Dashboards

Code libraries

Much more!

3

© All rights reserved. Zend Technologies, Inc.

RPG Examples

www.zend.com

Introduction to PHP

© All rights reserved. Zend Technologies, Inc.

PHP is a Scripting Language PHP Hypertext Pre-Processor

Developed initially by Rasmus Lerdorf in 1994: PHP/FI

Zeev Suraski and Andi Gutmans Contributing since1997+ (ZEev + aNDi = Zend)

Interpreted, not compiled

Forgiving and intuitive code structure (Short learning curve)

Immediate feedback during development

PHP is to Java what RPG is to COBOL

| 5 Geting Started with PHP on IBM i

Presenter
Presentation Notes
Change slide to reflect benefits

© All rights reserved. Zend Technologies, Inc.

What Is Zend Server? • Production quality PHP stack

PHP, ZF, DB connectivity, debugging extension, and more

• Three Editions – No charge “Basic Edition” provided by IBM & Full Professional and Enterprise commercial edition

All are production ready

• Application monitoring and diagnostics (integrated with Zend Studio)

• Multi-level performance enhancement capabilities

• Software updates and security hot fixes

• Easy and quick installation

• Zend Framework Integration

| 6 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

Zend Server

Zend Server Under the Covers

HTTP:10080 Apache Server (FastCGI)

IBM i

i/OS

DB2 UDB

PHP CGI

PHP file PASE

*PGM

CMD

ILE Apache:10080 • Default

configuration FastCGI

URL Request

HTML/response

| 7 Geting Started with PHP on IBM i

MySQL, SQL Server,

Oracle

Presenter
Presentation Notes
Move to right after Zend server for Ibm i

© All rights reserved. Zend Technologies, Inc.

Sample Scripts! (http://IBMi:10080/samples )

| 8 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc. | | 9 Geting Started with PHP on IBM i

Presenter
Presentation Notes
Move to after slide installation

© All rights reserved. Zend Technologies, Inc.

Sample Script – Hello World • Obligatory program when starting out

• Confirms correct setup of PHP

• Sample code: (Shortest PHP Macro around!)

• Save script in IFS /www/zendsvr6/htdocs /helloworld.php

• Browser URL: http://ibmisystem:10080/helloworld.php

| 10 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc. |

11 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

Basic file listing script (Update) • Connect to DB2 i

• Select records from a DB2 table

• Load the records in an HTML table

02/03/10

| 12 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

Connection to DB2 for i (Update) • Need three things:

System

User ID

Password

02/03/10

Note: If your data sets have *PUBLIC access, no user or password is required

| 13 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

Reading data...(Update) Loop through record set

02/03/10

| 14 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

Basic file listing script (Update)

02/03/10

| 15 Geting Started with PHP on IBM i

© All rights reserved. Zend Technologies, Inc.

RPG Examples

www.zend.com

Open Source Toolkit

© All rights reserved. Zend Technologies, Inc.

What is the toolkit?

•Set of classes that access IBM i native artifacts

•All Program Objects

RPG, COBOL, CL, etc.

•Others

Command processor

Data Queue’s

Spooled File

More…

•Access naturally from PHP code. No SP’s required

•Easy to use

17 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

New toolkit is Object Oriented

•Series of classes that “wrap” the IBM project

•All PHP but Object Oriented…(wait, there’s more!)

•Zend built the PHP wrapper

•No OO training required to use them!!!

•Sam Pinkhasov, Zend

19 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

XML Service

• IBM has open sourced XMLService.

•First Open Source project on IBM i. (that I know of…)

•Made up of RPG, CL and DB2 stored procedures (SQL)

•Tony Cairns, IBM Rochester

21 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

XML Service

•Cross platform

•Language agnostic

•Basic plumbing for all open source languages

22 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Compatibility Wrapper

• Intercepts existing i5 function requests

•Written in pure PHP

•Passes them on to OO PHP which then…

•Passes on to XML Service

•Alan Seiden, SBS & alanseiden.com

23 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Source Code for XML Service on YiPs…

24 Insert->Header & Footer

•http://youngiprofessionals.com/

© All rights reserved. Zend Technologies, Inc.

Source Code for PHP Toolkit on GitHub…

25 Insert->Header & Footer

•https://github.com/zendtech/IbmiToolkit

© All rights reserved. Zend Technologies, Inc.

PHP Classes

•Class where all wrapper functions start

Yes, this is OO but not too bad…

Look at it and poke around, It’s OK!

This is why we need the path set correctly

26 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Housekeeping…

•Need to set the extension and instantiate the object

Singleton pattern

Try & Catch

Can put this in your own include

27 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Now the program call

•Set parameters based on function

Call program

Output results

28 Insert->Header & Footer

I/O

Length

Comment

Var name

Init val

© All rights reserved. Zend Technologies, Inc.

AddParameterChar •Located in ToolkitService.php

/usr/local/zendsvr/share/ToolkitAPI

Uses CharParam which extends ProgramParam, etc…

29 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Before and after…Part 1 •Existing code call

30 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Before and after…Part 2 •New Open Source Toolkit program call

31 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Additional Parameter Types

• AddParameterInt32($io, $comment, $varName, $value, $dimension)

• AddParameterInt64($io, $comment, $varName, $value, $dimension)

• AddParameterUInt32($io, $comment, $varName, $value, $dimension)

• AddParameterUInt64($io, $comment, $varName, $value, $dimension)

• AddParameterFloat ($io, $comment, $varName, $value, $dimension)

• AddParameterReal($io, $comment, $varName, $value, $dimension)

• AddParameterPackdec($io, $length, $scale, $comment, $varName, $value, $dimension)

• AddParameterZoned($io, $length, $scale, $comment, $varName, $value, $dimension)

• AddParameterBin($io, $size, $comment, $varName, $value, $dimension)

• AddDataStruct($array, $parameters, $name=‘struct_name’, $dim, $by, $isArray, $labelLen)

32 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

RPG Examples

www.zend.com

Stored Procedure - Array

© All rights reserved. Zend Technologies, Inc.

Now an array

Data elements are nice, but…

Sometimes you need a little more…

How about an array of information?

34

© All rights reserved. Zend Technologies, Inc.

Have RPG build an array and use SQL…

35 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

SQL to create the SP & test in iNav CREATE PROCEDURE mpavlak/rpgsp2() LANGUAGE RPGLE

EXTERNAL NAME mpavlak/rpgsp2 GENERAL

36 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Test it in iNav…

37 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Now open results in PHP…

38 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Results in browser…

39 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

RPG Examples

www.zend.com

Stored Procedure – Record Set

© All rights reserved. Zend Technologies, Inc.

Have RPG build the result set and use SQL…

41 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

SQL to create the SP & test in iNav CREATE PROCEDURE mpavlak/rpgsp3() LANGUAGE RPGLE

EXTERNAL NAME mpavlak/rpgsp3 GENERAL

42 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Now open results in PHP…

43 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Results in browser…

44 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Zend Server Update

www.zend.com

Command processing & *libl

© All rights reserved. Zend Technologies, Inc.

Several ways to call commands…

•$conn->CLCommand(‘my command’);

•$conn->CLInteractiveCommand(‘DSP… command’);

•$conn->CLCommandWithOutput(‘RTV… command’);

© All rights reserved. Zend Technologies, Inc.

Other uses for the toolkit

•Command processing

Call CL command directly from toolkit

Retrieve response from command call

•Example

DSPLIBL

CHGLIBL

DSPLIBL

Useful for managing access to resource

• Files & Programs from RPG

47 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc. 48 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

PHP Code

49 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc. 50 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Zend Server Update

www.zend.com

Pricing Example

© All rights reserved. Zend Technologies, Inc.

Standard line discount

•RPG is black box, callable from nearly anywhere

•PHP has function to contain RPG call

•Routine to spin through line call for each quantity

52 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Mainline of code

53 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

CalcDiscount() Part 1

•Setup session for user-RPG program dedication

54 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

CalcDiscount() Part 2 •Create object, etc.

55 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

CalcDiscount() Part 3 •Call program

56 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Zend Server Update

www.zend.com

Miscellaneous Toolkit Points

© All rights reserved. Zend Technologies, Inc.

What was passed?

•Toolkit.ini setting

Debug = TRUE

•Turns on DebugOutput file

debugLogFile = "/usr/local/zendsvr/share/ToolkitApi/debug.log“

•Many other directive settings here

58 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Contents of output

59 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Stateful processing

•IPC

•Use session ID, for example • $PHPToolkitObj->setToolkitServiceParams ( array ('InternalKey' => "/tmp/$user" ) );

60 Insert->Header & Footer

© All rights reserved. Zend Technologies, Inc.

Zend Server Update

www.zend.com

Wrap it up

© All rights reserved. Zend Technologies, Inc.

Join us at

ZendCon Advancing the World of PHP

Conference Highlights

● Sessions designed for all knowledge levels

● Intensive tutorials for accelerated learning

● UnConference sessions for expanded topics

● PHP Certification crash course and 50% discount on certification exams

● Exhibit hall showcasing the latest products

● Networking opportunities with PHP community members and thought-leaders from around the world

w w w . z e n d c o n . c o m

Conference Tracks

● PHP Best Practices & Tooling Take home the latest tips and techniques for high-quality PHP apps

● Continuous Delivery & DevOps Explore best practices for high-velocity application delivery

● Application Architecture - APIs, Mobile, Cloud Services Learn how to harness the server-side and client-side revolutions

© All rights reserved. Zend Technologies, Inc. 63 Insert->Header & Footer

Q&A

www.zend.com

mike.p@zend.com

Please fill out your Session Evaluation!

Recommended