SlideShare una empresa de Scribd logo
1 de 90
Descargar para leer sin conexión
alanseiden.com
Alan Seiden Consulting
Bring RPG/COBOL business
logic to the web

with the PHP Toolkit
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Alan’s PHP on IBM i focus
• Consultant to innovative IBM i and PHP users
• PHP project leader, Zend/IBM Toolkit
• Contributor, Zend Framework DB2 enhancements
• Award-winning developer
• Authority, web performance on IBM i
2
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Founder, Club Seiden
3
club.alanseiden.com
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Contact information
4
Alan Seiden
alan@alanseiden.com
201-447-2437
alanseiden.com
twitter: @alanseiden
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Today’s toolkit topics
• A key component of modernization on IBM i
• How the toolkit came to be
• Who and how?
§ Open source on IBM i? Yes!
§ Community project

• Install/configure/use
• Program and command calls
• Performance
• Tips, troubleshooting, resources
5
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Toolkit connects
PHP to the i
6
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Access traditional ‘i’ resources from PHP
• Call RPG, COBOL, CL
§ Including IBM i APIs
§ Most popular use of toolkit

• Commands
§ ADDLIBLE LIB(MYLIB)
§ More command types (details later)

• Read/write objects that store data
§ Data areas
§ User spaces
• Send/receive data queues
• Get lists, read data or attributes from these:
§ Spooled files
§ Job logs
§ Active jobs
§ Objects
§ System values
7
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Testimonial
• “PHP and its IBM i Toolkit have enabled modern web
development with rich, complex user interfaces while retaining
our business logic on the back end
• “We have sent and received parameters with CL, RPG and
COBOL programs. We have also leveraged the CLCommand
function to submit jobs, manipulate library lists, retrieve job
logs and more.
• If there are limits, we have not encountered any, and it
performs very well.

—Stephanie Rabbani, senior web developer, BCD
8
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Call RPG/COBOL: adapt 5250 logic to the web
9
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Screen #1, Order header
10
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Screen #2, Order detail
11
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Screen #3, Content package from detail
(Option 4 from order header)
12
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Screen #4, Notes from order detail
F9 key launches this
13
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Web page combines all 4 “green screens”
14
RPG, COBOL,
System Resoures
PHP Application
Stored proc
Db2 calls
If we used stored procedures
Stored proc
Stored proc
Stored proc
Stored proc
Capabilities of stored procs
RPG, COBOL,
System Resources
XMLSERVICE
Your PHP code
Toolkit
Toolkit Methods
Sends XML
Toolkit architecture (no extra objects)
Also parses data structures
and more
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
XMLSERVICE
17
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Toolkit’s back-end: “XML Service”
• An IBM open source project for IBM i
• Written in RPG
• Like a generic stored procedure
§ Avoid hassle of creating individual stored procedures
§ Works via XML passed to/from it
§ Can handle complex data structures easily
• Tony Cairns, IBM Rochester
18
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
XML Service architecture
• Cross platform, accessible by all languages
• Expects parameters defined in XML
§ PHP toolkit handles the XML


<pgm name='ZZCALL' lib='MYLIB'>
<parm><data type='1A'>a</data></parm>
<parm><data type='1A'>b</data></parm>
<parm><data type='7p4'>11.1111</data></parm>
<parm><data type='12p2'>222.22</data></parm>
<parm><ds>
<data type='1A'>x</data>
<data type='1A'>y</data>
<data type='7p4'>66.6666</data>
<data type='12p2'>77777.77</data>
</ds>
</parm>
<return><data type='10i0'>0</data></return>
</pgm>
19
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Toolkit
20
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Collaborative
• Free and Open Source Software (FOSS)
§ Source code is there—read it, learn, extend, give feedback
§ Open source on IBM i appeals to young developers
• Community involvement
§ People are contributing enhancements and fixes (PHP and RPG
code). Luca Zovi, Martin Hieden. Tell us your ideas
21
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
A few of our contributors so far
22
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Is it really free?
• Yes!
§ BSD license (business friendly)
• http://en.wikipedia.org/wiki/BSD_licenses
§ Source code available to all
• Community code contributions welcome
• Inner workings of toolkit revealed—nothing hidden
§ Fast problem resolution...sometimes in hours 

• No registration or special license required
§ (Zend Server itself does require at least a free license)

• Never a “nag” message
§ Your QSYSOPR message queue can relax
23
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Toolkits shipped by Zend (then and now)
• 2006-2011: i5 Toolkit (Easycom)
§ No longer shipped with Zend Server
§ May still be used if already installed
§ Remains available commercially from Aura company
• 2012+: Open Source Toolkit
§ Made of pure PHP and RPG, free and open source
§ Functionality similar to i5 Toolkit
§ Includes a Compatibility Wrapper (CW), developed by me, to ease
transition to new toolkit
24
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
PHP toolkit talks to XMLSERVICE
• PHP talks to XMLSERVICE
through generic stored
procedures (installed
automatically)

• Any environment that can send/
receive XML can use
XMLSERVICE 

• PHP was the first major “client” to
use XMLSERVICE but others are
here now (e.g. PowerRuby,
Node.js, .NET), strengthening
XMLSERVICE as a back-end
25
RPG, COBOL,
System Resources
XMLSERVICE
PHP Application
Toolkit
Toolkit Methods
XML, Stored Procedures
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Install and
configure
26
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Several ways to get toolkit
• Zend Server
• Official, tested release packaged in Zend Server

• Young i Professionals (YiPs) site
•Various levels of testing done
•Install from source code
• Github (PHP front-end only)
• Details coming up
27
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Zend Server for IBM i
• Download Zend Server 8.x
• http://www.zend.com/en/products/server/downloads-ibmi
• Easy upgrade from 6.x
• Includes latest approved toolkit
• Requires IBM i 6.1 and up









• Editions
• http://www.zend.com/en/products/server/editions
• Basic (free), Professional, Enterprise
• Same download, different license
28
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Get current PTFs within your release
•Latest DB2 for IBM i group PTF level for your release
§ 6.1: WRKPTFGRP SF99601
§ 7.1: WRKPTFGRP SF99701
§ 7.2: WRKPTFGRP SF99702
§ For the latest levels: 

http://www-947.ibm.com/systems/support/i/fixes/

and click Group PTFs
29
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
New versions on YiPs
• Young i Professionals (YiPs) site
•http://youngiprofessionals.com/wiki/XMLSERVICE
•Install from source code
•Two parts: RPG and PHP
• Installation instructions are on the site
30
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
“Bleeding edge” also on YiPs
• Test versions of XMLSERVICE
§ “For brave and helpful only”
§ Rapid releases to resolve issues or add functionality
§ http://174.79.32.155/wiki/index.php/XMLSERVICE/XMLSERVICETesting
• Look under

“Active test versions”
31
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
YiPs installation location
• Choose XMLSERVICE installation library
•CRTXML compiles into XMLSERVICE test library
• If use test library, configure with toolkit.ini’s “XMLServiceLib”
•CRTXML2 compiles into ZENDSVR production library
•CRTXML6 compiles into ZENDSVR6 production library
• Standard directory for PHP toolkit code
•/usr/local/zendsvr(6)/share/ToolkitApi
•“zendsvr6” for Zend Server 6.x
32
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
GitHub is latest home to the toolkit
• Front-end PHP part of toolkit is now managed on Github
• Community can enter issues, submit pull requests, add examples
• Composer and Packagist…getting close!
• https://github.com/zendtech/IbmiToolkit
33
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Verify installation: run demo scripts
§ Deploy the sample scripts:
• http://files.zend.com/help/Zend-Server-IBMi/content/
i5_installing_sample_scripts_ibmi.htm
34
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Program calls
35
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Calling demo script with result
Call_program_RPG.html
Click “Call program” to pass parameter to PHP and then RPG
36
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
RPG program from ZENDSVR samples
File: ZENDSVR/QRPGLESRC Member: COMMONPGM
C *ENTRY PLIST
C PARM CODE 10
C PARM NAME 10
******************************************************
C CODE IFEQ '1'
C movel 'IBM' name
C ELSE
C CODE IFEQ '2'
C movel 'Zend' name
C ELSE
C movel 'wrong code' name
C ENDIF
C ENDIF
C*
C SETON LR
C RETURN
37
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
PHP to call it
/www/zendsvr/htdocs/Samples/Toolkit/Call_RPG_example.php
Call_RPG_example.php
38
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
AddParameterChar in detail
AddParameterChar() is defined in ToolkitService.php
I
/
O
Le
ng
th
C
o
m
m
en
t
V
ar
n
a
m
e
Ini
t
va
l
function AddParameterChar(

$io, $size, $comment, $varName = '', $value, $varying, $dimension)
Our example:
39
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
More parameter types
AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension)
AddParameterInt16($io, $comment, $varName, $value, $dimension) [5i0 ints]
AddParameterInt32($io, $comment, $varName, $value, $dimension) [10i0 ints]
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)
40
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Additional program call features
•PCML parameter definitions (optional)
•Complex data structures
•Arrays and output counter fields
•Service programs, procedures, return values
41
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Common question
•“My RPG data structures are complex. Is there a shortcut to
creating the PHP parameters?”
•“I am a PHP developer. I don’t understand the RPG data types.
My RPG programmer doesn’t know how to explain.”

•The solution is here!
42
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
New RPG-to-PHP parameter mapping tool
•http://yips.idevcloud.com/Samples/DSpecTool/
•Creates PHP code based on D Specs
•Open source: https://bitbucket.org/inext/xmlservice-rpg
43
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Paste the RPG code
44
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Voila…parameters in PHP
45
•Creates perfect parameters, including any procedure name
•You may have to adjust the order for data structures
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Commands
46
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Several ways to call commands
$conn->CLCommand(‘my command’);
$conn->CLInteractiveCommand(‘DSP.... command’);
$conn->CLCommandWithOutput(‘RTV... command’);
Details ahead...
47
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Simple command
// CLCommand to add library list entry
$cmdString = ‘ADDLIBLE LIB(ALANLIB)’;
$success = $conn->CLCommand($cmdString);
if($success) {
echo ‘Added library’;
} else {
echo ‘Error: ’ . $conn->getErrorMsg();
}
48
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Interactive command output
$cmdString = ‘DSPLIBL’;
// CLInteractiveCommand returns “screen” results
$liblArray = $conn->CLInteractiveCommand ($cmdString);
if($liblArray) {
// output full result of DSPLIBL command in an array
// <pre> </pre> formats the array
echo '<PRE>' . print_r($liblArray, true) . '</PRE>';
}
Results on next slide...
49
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Results of DSPLIBL
Array
(
[0] => 5770SS1 V7R1M0 100423 Library List 3/19/12 8:52:44 Page 1
[1] => ASP
[2] => Library Type Device Text Description
[3] => QSYS SYS System Library
[4] => QSYS2 SYS System Library for CPI's
[5] => QHLPSYS SYS
[6] => QUSRSYS SYS System Library for Users
[7] => DBU80 SYS
[8] => QSYS38 SYS
[9] => DC@EPC03 USR EPC-814 DC@ADKPGM
[10] => ZENDSVR USR
[11] => QGPL USR General Purpose Library
[12] => QTEMP USR
[13] => * * * * * E N D O F L I S T I N G * * * * *
)
50
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Get info with RTV* commands
CLCommandWithOutput() gets output from RTVJOBA, RTVOBJD,
RTVUSRPRF...
public function getJobAttributes() {
// Note: specify (?N) for numeric attributes
$cmdString = 'RTVJOBA JOB(?) USER(?) NBR(?) CURUSER(?) SYSLIBL(?)
CURLIB(?) USRLIBL(?) LANGID(?) CNTRYID(?) CCSID(?N) DFTCCSID(?N)';

// Send command; get output array of key/value pairs
$outputArray = $this->ClCommandWithOutput($cmdString);

return $outputArray;
} //(public function getJobAttributes())
$attrs = $conn->getJobAttributes(); // run command
echo ‘<pre>’ . print_r($attrs, true) . ‘</pre>’; // print_r() formats arrays
Results on next slide...
51
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Output from RTVJOBA
Array of job attributes
Array(

[JOB] => QSQSRVR

[USER] => QUSER

[NBR] => 240164

[CURUSER] => QTMHHTTP

[SYSLIBL] => QSYS QSYS2 QUSRSYS
[CURLIB] => *NONE

[USRLIBL] => QTEMP QGPL MYUTIL

[LANGID] => ENU

[CNTRYID] => US

[CCSID] => 37

[DFTCCSID] => 37
)
52
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


More examples
53
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
List of output queues
54
// includes ToolkitService.php as well
require_once('iToolkitService.php');
// connect to toolkit
$conn = ToolkitService::getInstance('*LOCAL', '', '');
$conn->setOptions(array('stateless' => true));
// instantiate our object-finder object.
$objectList = new ObjectLists($conn);
// getObjectList returns an array. Each element is a 30-char string.
// 10 chars for object name; 10 for library; 10 for type.
$outqItems = $objectList->getObjectList('*ALL', '*ALL', '*OUTQ');
// Parse the name and library.
$outqNameLibs = array();
foreach ($outqItems as $outqItem) {
$nameAndLib['name'] = substr($outqItem, 0, 10);
$nameAndLib['lib'] = substr($outqItem, 10, 10);
$outqNameLibs[] = $nameAndLib;
} //(foreach ($outqItems as $outqItem))
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Output queue display
55
by var_dump’ing $outqNameLibs
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Array of data structures
56
•See example here: http://forums.zend.com/viewtopic.php?
f=113&t=105248
•Important snippets here:
// Subfields for data structure
// Here's a character field array, size 3, that's part of the DS
$ds[] = $conn->AddParameterChar('both', 21,'Part', 'PTPRT', ‘’)
->setParamDimension(3); // three records
// DSCOUNT is a counter field. Value is set by RPG/COBOL program. Value will control the number
of MULTDS fields that return (see data structure MULTDS below)
$param[] = $conn->AddParameterZoned('both', 5, 0, 'how many MULTDS array elements actually
return', 'DSCOUNT', 6)->setParamLabelCounter('DSCOUNT');
// Multi-occurrence data structure with maximum dimension set to 100 but whose final output count
will be determined by DSCOUNT. field names arbitrary. Name them whatever you wish
$param[] = $conn->AddDataStruct($ds, 'MULTDS')
->setParamDimension(100) // max of 100 records
->setParamLabelCounted('DSCOUNT');
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Read a data area
57
require_once(‘iToolkitService.php’);
// set up name of data area
$dataAreaObj = new DataArea($ToolkitServiceObj);
$dataAreaObj->setDataAreaName('MYLIB', 'MYDTAARA');
// read it
$value = $dataAreaObj->readDataArea(1, '*ALL'); // offset and length
// output string value from data area
echo $value;
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Connecting
58
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Basic connection
• Connect with database, user, password
• Try *LOCAL or real database name
• WRKRDBDIRE shows valid names
• If leave blank (‘’, ‘’, ‘’): connect with default web user
• QTMHHTTP

59
<?php
// bring in the toolkit
require_once('ToolkitService.php');
// connect to local IBM i
$conn = ToolkitService::getInstance('*LOCAL', 'MYUSER', ‘MYPASS’);

// specify stateless mode (simple: no internal key needed)
$conn->setOptions(array('stateless'=>true));
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Choice of stateless or stateful (private)
• Easiest way to start: stateless
§ Quicker initial connection, runs tookit directly in DB2 job (QSQSRVR job)
§ No guarantee that you’ll get same job from pool
§ Share QTEMP between SQL and RPG (runs in DB2 job)
§ Specify ‘stateless’
$conn=>setOptions(array(‘stateless’=>true));
• Advanced: stateful/private
§ A new job is started and “reserved” for re-use
§ Retains file cursors (READE position), QTEMP, LIBL, open file handles
§ Best performance when many program calls
§ Specify ‘InternalKey’ as unique job identifier
$conn=>setOptions(array(‘InternalKey=>‘/tmp/jim123’));

60
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Safety first
61
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Prevent RPG/COBOL errors from hanging
• “Message waiting” Inquiry messages are to be avoided
• It seems “normal” for errors to pop up in a green screen
• “Record lock,” “Add more records to file?” “Level check”
• Find them with DSPMSG MSGQ(QSYSOPR) MSGTYPE(*INQ)
• If an RPG/CL does not complete, it won’t return control
• Web page will “hang” till it times out or operator ends
job
• If operator ends job, further requests may go nowhere
• Three techniques coming up—aside from not allowing
faulty programs in production
62
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
1. Wrap program in CL having MONMSG
• Wrap RPG/COBOL call in a CL (control language)
program containing a MONMSG statement. Example:
PGM PARM(&PGMNAME &ERRORFL)
DCL &PGMNAME *CHAR 10
DCL &ERRORFL *CHAR 1
/* if any error, end and return error code ‘1’ */
CALL PGM(&PGMNAME)
MONMSG CPF0000 EXEC(GOTO $ERROR)
CHGVAR &ERRORFL '0'
RETURN
$ERROR:
CHGVAR &ERRORFL '1'
ENDPGM
63
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
2. Toolkit timeout technique
// give RPG/COBOL 15 seconds to complete before we give up and
end the program, so that PHP doesn't 'hang'.
$options = array('stateless' => true,
'customControl' => '*call(15/kill/server)');
$conn->setOptions(array($options));
64
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
3. Set a global reply via System reply list
• CHGJOB INQMSGRPY(*SYSRPYL)
• WRKRPYLE, ADDRPYLE
65
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Resources, events,
Q&A
66
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Resources
• Alan’s toolkit page with links to other resources
• http://alanseiden.com/toolkit

• Young i Professionals site
• http://youngiprofessionals.com/wiki/XMLSERVICE

• Zend Toolkit Forum
• http://forums.zend.com/viewforum.php?f=113
• “PHP on IBM i”->”Zend Server for IBM i”->”New Toolkit”
• Zend toolkit manual
• http://files.zend.com/help/Zend-Server-IBMi/zend-
server.htm#php_toolkit_xml_service_functions.htm
• Github site
• https://github.com/zendtech/IbmiToolkit
67
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Try the toolkit and get to web/mobile
68
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
A community resource: get involved
• Help us enhance the toolkit
§ Report any issues on the Forum

• Contribute enhancements, tips, fixes
§ Write to forum or alan@alanseiden.com
• Why?
§ Make the toolkit and IBM i platform better for everyone
§ Sharpen your skills; work with great people J
§ Working with open source demonstrates commitment to your chosen
platform and your career as a whole
69
alanseiden.com
Alan Seiden Consulting
PHP Toolkit for IBM i
technical details
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
To check XMLSERVICE version
call qp2term
qsh -c /qsys.lib/zendsvr6.lib/xmlver.pgm
returns something like:
XML Toolkit 1.9.1$
Make sure it’s at least 1.8.5. Critical bug was fixed in 1.8.0. (If the
“xmlver” program not found, your XMLSERVICE is too old!)
71
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
How to use persistent DB2 connection
• See “DB2 and PHP Best Practices on IBM i”
• Persistent DB connection
§ $conn = ToolkitService::getInstance(‘*LOCAL’, ‘myuser’, ‘mypw’, ‘’, true);
§ Fifth param is persistence flag
§ Or re-use an existing DB2 persistent connection
// connect to db. Make sure i5 naming mode matches between DB2 and toolkit
$namingMode = DB2_I5_NAMING_ON; // ON or OFF
$db = db2_pconnect('DBNAME', 'user', 'pass', array('i5_naming' => $namingMode));
// Connect to Zend API, passing db resource and i5 naming mode instead of dbname/
user/password.
$conn = ToolkitService::getInstance($db, $namingMode);
72
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Useful settings in toolkit.ini
• Located in /usr/local/zendsvr(6)/share/ToolkitApi
• Useful settings:
•[system]
• Debug=true
• Creates debug.log
• XMLServiceLib = "ZENDSVR6“
• Or = “XMLSERVICE”
• Lets you try new versions safely
73
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
How to check or set CCSID
• DSPSYSVAL QCCSID
•If not 65535, you’re probably OK
•Change with CHGSYSVAL SYSVAL(QCCSID) VALUE(xyz)
• or in Apache config: /www/zendsvr(6)/conf/httpd.conf
•USA settings:
• DefaultFsCCSID 37

CGIJobCCSID 37
•Different outside of USA. Check list of “Job CCSID”:
• http://www-03.ibm.com/systems/i/software/globalization/default_list.html 

• Everyone must set a CCSID
•This really means YOU.....otherwise toolkit will not work
•I mean it J
• P.S. Please set your CCSID
74
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Connect from

“off the box”
75
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
2-tier = Run PHP on Windows/Linux/Mac
• A common developer request
• Develop on laptop
§ Connect to XMLSERVICE on IBM i; then deploy PHP code to IBM i
with no code changes
• Or run production PHP on non-i machine, calling IBM i-
based RPG, commands, etc.
• Never a charge or cost for this 2-tier support
§ All free and open source
76
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Alternatives for 2-tier transports
• DB2 Connect and ODBC
§ “DB2 Connect” software from IBM (paid software)
• Advantage: handles SQL queries, too, as if they were local to PC
§ No-charge alternative: ODBC (free with IBM i Access)
• Other alternatives
§ CGI/HTTP (no drivers needed)
§ Many more are possible because XML can be sent over any type of
connection
77
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Connect via ODBC
• First, set up ODBC database config on your PC
§ Connection name will be used as the db name (*LOCAL is not allowed)
§ Documentation: http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/
index.jsp?topic=%2Frzaii%2Frzaiiodbc04.htm
• New API style connection
$conn = ToolkitService::getInstance(‘MYODBCCONN’, ‘myuser’,
‘mypw’, ‘odbc’);
• CW style connection
§ Specify database name in toolkit.ini
[hosts]
myibmi = MYODBCCONN 

// PHP to connect via ODBC
$options = array(CW_TRANSPORT_TYPE=>’odbc’);
$conn = i5_connect(‘myibmi’, ‘myuser’, ‘mypw’, $options);
78
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
HTTP transport
• HTTP/CGI interface, no drivers needed (1.5.0+)
• Not enabled by default (secure)
§ See http://www.youngiprofessionals.com/wiki/XMLSERVICE
§ “Optional XMLSERVICE REST interface via RPG CGI (xmlcgi.pgm)”
• Point to it with toolkit.ini
79
[transport]
; transport type allows configuration of transport from this INI.
transportType = "http" ; ibm_db2 is default. Other choices: "odbc", "http"
; for http transport only
httpTransportUrl = "http://example.com/cgi-bin/xmlcgi.pgm"
; default plug size (expected output size): 4K, 32K, 512K (default), 65K, 512K, 1M, 5M, 10M, 15M
; can also change in code with $conn->setOptions(array('plugSize' => '4K')); or desired size
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Performance
“do”s and “don’t”s
80
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Performance “don’t”s
• Don’t use disconnect() unless it’s the end of the day,
logout, etc.
• Reconnection in stateful mode is slow
• Official samples set a bad example here
• Don’t allow inquiry messages to arise, hanging your job
(and maybe more)
• See MONMSG and related topics to prevent this
• Don’t run commands or programs that might return an
error to the toolkit
• Example: ADDLIBLE can return “already exists” error. Prefer
CHGLIBL or other technique
• Toolkit will fetch joblog for error reporting, which can be slow
• Not XMLSERVICE’s fault…in future we may allow “fast” (no joblog)
mode sometimes for non-critical errors
81
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Performance “do”s
• Do use the proper connection option
• Stateless: usually simplest and best. No new jobs needed
• Stateful (InternalKey): requires care in choosing IPC key, and not
disconnecting too often
• Do set plugSize as small as possible for the expected
data
• $conn->setOptions(array(‘plugSize’=>’4K’)); // minimum
• Others are 32K, 512K, 65K, 512K, 1M, 5M, 10M, 15M
• Do use a persistent db2 connection that you share with
the toolkit
• See previous slide: “How to use persistent DB2 connection”
• Do combine multiple command and program calls in a
single CL program, then call the CL from the toolkit
• Also wrap “RTV*” commands in CL
82
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Troubleshooting
83
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Retrieve error code and message
• getErrorCode(), getErrorMsg()
• These will return a CFP-type code and descriptive
message obtained from the joblog

echo 'Problem calling program. Code: ’
. $conn->getErrorCode() . '. Text: '
. $conn->getErrorMsg();
Problem calling program. Code: RNX1216 Text:
Error message CPF4103 appeared during OPEN for
file MNG111FM
84
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Troubleshooting tips
• Get latest toolkit version
§ Start with Zend Server download site
§ or latest XMLSERVICE and PHP wrapper
• http://www.youngiprofessionals.com/wiki/XMLSERVICE
§ Test in XMLSERVICE library if unsure

• Use Z-Ray
§ View returned XML including joblog if an error occurred

• Create debug log
§ In toolkit.ini, set debug=true, then run script again
• Creates /usr/local/zendsvr6/share/toolkitapi/debug.log
• debug.log contains all XML send/received, connection info
• Tip: to split into daily logs, specify:

$conn->setOptions(array('debug'=>true, 'debugLogFile' =>'/usr/
local/zendsvr6/var/log/toolkit_debug' . date("Ymd") . '.log'));
85
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Z-Ray will speed development
• Shows every query and time for each query
• Toolkit extension for Z-Ray shows each program call,
input/output, timing
• Save time otherwise spent hunting in debug logs!
86
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Interactively debug RPG or COBOL program
1. Add the following line to your PHP script before the program call to be debugged.
$toolkitConn should be your toolkit connection object.
$toolkitConn->setOptions(array(‘customControl'=>'*debug'));
Run your script. The script will "hang" while it waits on #2 below...(move to green
screen 5250 for steps 2-10)
2. A MSGW inquiry message in DSPMSG QSYSOPR will be generated by the toolkit.
3. Note the job information (number, name, user) provided in the MSGW.
4. STRSRVJOB using that job information as parameters.
5. STRDBG with the program and library you wish to debug.
6. Answer the MSGW. Any answer will do--"G" is fine.
7. The RPG program source will appear in debug mode in your terminal,
ready to step through, allowing you to inspect variables, etc.
8. When done inspecting and stepping, let the RPG program complete (using
function keys indicated on screen).
9. ENDDBG
10. ENDSRVJOB
87
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting


Future of toolkit
88
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
The latest
• PHP toolkit version 1.6.1 / XMLSERVICE 1.9.2
§ Faster
§ Experimental “fetch data via recordset” so that plugSize may not be
needed in future
• Future
§ Always faster and faster
§ Further improvements for ease of use
§ Samples on GitHub
Full list of current improvements:
http://174.79.32.155/wiki/index.php/XMLSERVICE/XMLSERVICEChangeLog

http://174.79.32.155/wiki/index.php/XMLSERVICE/CWChangeLog

89
PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting
Contact and get tips
Alan Seiden
Alan Seiden Consulting
Ho-Ho-Kus, NJ
90
alan@alanseiden.com ● 201-447-2437 ● twitter: @alanseiden
Free PHP tips: 

http://alanseiden.com/tips

Más contenido relacionado

La actualidad más candente

From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iAlan Seiden
 
IBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP DevelopersIBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP DevelopersAlan Seiden
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend frameworkAlan Seiden
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i Zend by Rogue Wave Software
 
PHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel TourPHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel TourRod Flohr
 
Install MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and moreInstall MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and moreRod Flohr
 
Running open source PHP applications on you IBM i
Running open source PHP applications on you IBM iRunning open source PHP applications on you IBM i
Running open source PHP applications on you IBM iProximity Group
 
Zend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZendCon
 
PHP on Windows - What's New
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's NewZendCon
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZendCon
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudZendCon
 
Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Mark Ginnebaugh
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginnersAdam Englander
 
Web Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureWeb Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureToru Kawamura
 

La actualidad más candente (19)

From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm i
 
IBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP DevelopersIBM i: Fertile Ground for PHP Developers
IBM i: Fertile Ground for PHP Developers
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
 
Performance tuning with zend framework
Performance tuning with zend frameworkPerformance tuning with zend framework
Performance tuning with zend framework
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
PHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel TourPHP Installed on IBM i - the Nickel Tour
PHP Installed on IBM i - the Nickel Tour
 
Install MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and moreInstall MariaDB on IBM i - Tips, troubleshooting, and more
Install MariaDB on IBM i - Tips, troubleshooting, and more
 
Running open source PHP applications on you IBM i
Running open source PHP applications on you IBM iRunning open source PHP applications on you IBM i
Running open source PHP applications on you IBM i
 
Zend_Tool: Practical use and Extending
Zend_Tool: Practical use and ExtendingZend_Tool: Practical use and Extending
Zend_Tool: Practical use and Extending
 
PHP on Windows - What's New
PHP on Windows - What's NewPHP on Windows - What's New
PHP on Windows - What's New
 
Zend Core on IBM i - Security Considerations
Zend Core on IBM i - Security ConsiderationsZend Core on IBM i - Security Considerations
Zend Core on IBM i - Security Considerations
 
PHP and Platform Independance in the Cloud
PHP and Platform Independance in the CloudPHP and Platform Independance in the Cloud
PHP and Platform Independance in the Cloud
 
Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51Getting Started with SQL Server Compact Edition 3.51
Getting Started with SQL Server Compact Edition 3.51
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
Require js training
Require js trainingRequire js training
Require js training
 
Performance tuning PHP on IBMi
Performance tuning PHP on IBMiPerformance tuning PHP on IBMi
Performance tuning PHP on IBMi
 
Web Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the futureWeb Clients for Ruby and What they should be in the future
Web Clients for Ruby and What they should be in the future
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 

Destacado

Php arrays for RPG programmers
Php arrays for RPG programmersPhp arrays for RPG programmers
Php arrays for RPG programmersCOMMON Europe
 
Caries risk assessment
Caries risk assessmentCaries risk assessment
Caries risk assessmentElena Torn
 
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.abas_lb
 
Alex montalvo 120716
Alex montalvo 120716Alex montalvo 120716
Alex montalvo 120716Alex Montalvo
 
Rakesh sr dwh_bi_consultant resume
Rakesh sr dwh_bi_consultant resumeRakesh sr dwh_bi_consultant resume
Rakesh sr dwh_bi_consultant resumeRakesh Kumar
 

Destacado (12)

Php arrays for RPG programmers
Php arrays for RPG programmersPhp arrays for RPG programmers
Php arrays for RPG programmers
 
IanPerrymanResume
IanPerrymanResumeIanPerrymanResume
IanPerrymanResume
 
Sandeep_MF_4+years of exp
Sandeep_MF_4+years of expSandeep_MF_4+years of exp
Sandeep_MF_4+years of exp
 
J. M. Hoffman
J. M. HoffmanJ. M. Hoffman
J. M. Hoffman
 
Resume Paul Vlasek3
Resume Paul Vlasek3Resume Paul Vlasek3
Resume Paul Vlasek3
 
Caries risk assessment
Caries risk assessmentCaries risk assessment
Caries risk assessment
 
RESUME_VAIBHAV_PATHARE
RESUME_VAIBHAV_PATHARERESUME_VAIBHAV_PATHARE
RESUME_VAIBHAV_PATHARE
 
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.
Cariology and caries risk assessment. by Dr.Kazhan O. abdulrahman.
 
Alex montalvo 120716
Alex montalvo 120716Alex montalvo 120716
Alex montalvo 120716
 
Rakesh sr dwh_bi_consultant resume
Rakesh sr dwh_bi_consultant resumeRakesh sr dwh_bi_consultant resume
Rakesh sr dwh_bi_consultant resume
 
Dental indices
Dental indicesDental indices
Dental indices
 
Tooth brushing techniques
Tooth brushing techniquesTooth brushing techniques
Tooth brushing techniques
 

Similar a PHP Toolkit from Zend and IBM: Open Source on IBM i

PHP - Programming language war, does it matter
PHP - Programming language war, does it matterPHP - Programming language war, does it matter
PHP - Programming language war, does it matterMizno Kruge
 
Ria Applications And PHP
Ria Applications And PHPRia Applications And PHP
Ria Applications And PHPJohn Coggeshall
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZFRalph Schindler
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructuremkherlakian
 
Introduction to column oriented databases in PHP
Introduction to column oriented databases in PHPIntroduction to column oriented databases in PHP
Introduction to column oriented databases in PHPZend by Rogue Wave Software
 
Red Hat for IBM System z IBM Enterprise2014 Las Vegas
Red Hat for IBM System z IBM Enterprise2014 Las Vegas Red Hat for IBM System z IBM Enterprise2014 Las Vegas
Red Hat for IBM System z IBM Enterprise2014 Las Vegas Filipe Miranda
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Stefan Koopmanschap
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIvo Jansch
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHPEric Johnson
 
Unleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ PlatformUnleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ PlatformSébastien Morel
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
 
Perl in the Real World
Perl in the Real WorldPerl in the Real World
Perl in the Real WorldOpusVL
 

Similar a PHP Toolkit from Zend and IBM: Open Source on IBM i (20)

PHP - Programming language war, does it matter
PHP - Programming language war, does it matterPHP - Programming language war, does it matter
PHP - Programming language war, does it matter
 
Lamp Zend Security
Lamp Zend SecurityLamp Zend Security
Lamp Zend Security
 
Ria Applications And PHP
Ria Applications And PHPRia Applications And PHP
Ria Applications And PHP
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
 
Ipc mysql php
Ipc mysql php Ipc mysql php
Ipc mysql php
 
Introduction to column oriented databases in PHP
Introduction to column oriented databases in PHPIntroduction to column oriented databases in PHP
Introduction to column oriented databases in PHP
 
Red Hat for IBM System z IBM Enterprise2014 Las Vegas
Red Hat for IBM System z IBM Enterprise2014 Las Vegas Red Hat for IBM System z IBM Enterprise2014 Las Vegas
Red Hat for IBM System z IBM Enterprise2014 Las Vegas
 
A Tale of Two Toolkits
A Tale of Two ToolkitsA Tale of Two Toolkits
A Tale of Two Toolkits
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
 
green
greengreen
green
 
Integrating PHP With System-i using Web Services
Integrating PHP With System-i using Web ServicesIntegrating PHP With System-i using Web Services
Integrating PHP With System-i using Web Services
 
Zend Framwork configurations
Zend Framwork configurationsZend Framwork configurations
Zend Framwork configurations
 
Zend Code in ZF 2.0
Zend Code in ZF 2.0Zend Code in ZF 2.0
Zend Code in ZF 2.0
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Unleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ PlatformUnleash your Symfony projects with eZ Platform
Unleash your Symfony projects with eZ Platform
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
Perl in the Real World
Perl in the Real WorldPerl in the Real World
Perl in the Real World
 
Zend
ZendZend
Zend
 
Zend Framwork presentation
Zend Framwork presentationZend Framwork presentation
Zend Framwork presentation
 

Último

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Último (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

PHP Toolkit from Zend and IBM: Open Source on IBM i

  • 1. alanseiden.com Alan Seiden Consulting Bring RPG/COBOL business logic to the web
 with the PHP Toolkit
  • 2. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Alan’s PHP on IBM i focus • Consultant to innovative IBM i and PHP users • PHP project leader, Zend/IBM Toolkit • Contributor, Zend Framework DB2 enhancements • Award-winning developer • Authority, web performance on IBM i 2
  • 3. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Founder, Club Seiden 3 club.alanseiden.com
  • 4. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Contact information 4 Alan Seiden alan@alanseiden.com 201-447-2437 alanseiden.com twitter: @alanseiden
  • 5. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Today’s toolkit topics • A key component of modernization on IBM i • How the toolkit came to be • Who and how? § Open source on IBM i? Yes! § Community project
 • Install/configure/use • Program and command calls • Performance • Tips, troubleshooting, resources 5
  • 6. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Toolkit connects PHP to the i 6
  • 7. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Access traditional ‘i’ resources from PHP • Call RPG, COBOL, CL § Including IBM i APIs § Most popular use of toolkit
 • Commands § ADDLIBLE LIB(MYLIB) § More command types (details later)
 • Read/write objects that store data § Data areas § User spaces • Send/receive data queues • Get lists, read data or attributes from these: § Spooled files § Job logs § Active jobs § Objects § System values 7
  • 8. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Testimonial • “PHP and its IBM i Toolkit have enabled modern web development with rich, complex user interfaces while retaining our business logic on the back end • “We have sent and received parameters with CL, RPG and COBOL programs. We have also leveraged the CLCommand function to submit jobs, manipulate library lists, retrieve job logs and more. • If there are limits, we have not encountered any, and it performs very well.
 —Stephanie Rabbani, senior web developer, BCD 8
  • 9. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Call RPG/COBOL: adapt 5250 logic to the web 9
  • 10. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Screen #1, Order header 10
  • 11. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Screen #2, Order detail 11
  • 12. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Screen #3, Content package from detail (Option 4 from order header) 12
  • 13. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Screen #4, Notes from order detail F9 key launches this 13
  • 14. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Web page combines all 4 “green screens” 14
  • 15. RPG, COBOL, System Resoures PHP Application Stored proc Db2 calls If we used stored procedures Stored proc Stored proc Stored proc Stored proc Capabilities of stored procs
  • 16. RPG, COBOL, System Resources XMLSERVICE Your PHP code Toolkit Toolkit Methods Sends XML Toolkit architecture (no extra objects) Also parses data structures and more
  • 17. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting XMLSERVICE 17
  • 18. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Toolkit’s back-end: “XML Service” • An IBM open source project for IBM i • Written in RPG • Like a generic stored procedure § Avoid hassle of creating individual stored procedures § Works via XML passed to/from it § Can handle complex data structures easily • Tony Cairns, IBM Rochester 18
  • 19. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting XML Service architecture • Cross platform, accessible by all languages • Expects parameters defined in XML § PHP toolkit handles the XML 
 <pgm name='ZZCALL' lib='MYLIB'> <parm><data type='1A'>a</data></parm> <parm><data type='1A'>b</data></parm> <parm><data type='7p4'>11.1111</data></parm> <parm><data type='12p2'>222.22</data></parm> <parm><ds> <data type='1A'>x</data> <data type='1A'>y</data> <data type='7p4'>66.6666</data> <data type='12p2'>77777.77</data> </ds> </parm> <return><data type='10i0'>0</data></return> </pgm> 19
  • 20. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Toolkit 20
  • 21. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Collaborative • Free and Open Source Software (FOSS) § Source code is there—read it, learn, extend, give feedback § Open source on IBM i appeals to young developers • Community involvement § People are contributing enhancements and fixes (PHP and RPG code). Luca Zovi, Martin Hieden. Tell us your ideas 21
  • 22. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting A few of our contributors so far 22
  • 23. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Is it really free? • Yes! § BSD license (business friendly) • http://en.wikipedia.org/wiki/BSD_licenses § Source code available to all • Community code contributions welcome • Inner workings of toolkit revealed—nothing hidden § Fast problem resolution...sometimes in hours 
 • No registration or special license required § (Zend Server itself does require at least a free license)
 • Never a “nag” message § Your QSYSOPR message queue can relax 23
  • 24. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Toolkits shipped by Zend (then and now) • 2006-2011: i5 Toolkit (Easycom) § No longer shipped with Zend Server § May still be used if already installed § Remains available commercially from Aura company • 2012+: Open Source Toolkit § Made of pure PHP and RPG, free and open source § Functionality similar to i5 Toolkit § Includes a Compatibility Wrapper (CW), developed by me, to ease transition to new toolkit 24
  • 25. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting PHP toolkit talks to XMLSERVICE • PHP talks to XMLSERVICE through generic stored procedures (installed automatically)
 • Any environment that can send/ receive XML can use XMLSERVICE 
 • PHP was the first major “client” to use XMLSERVICE but others are here now (e.g. PowerRuby, Node.js, .NET), strengthening XMLSERVICE as a back-end 25 RPG, COBOL, System Resources XMLSERVICE PHP Application Toolkit Toolkit Methods XML, Stored Procedures
  • 26. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Install and configure 26
  • 27. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Several ways to get toolkit • Zend Server • Official, tested release packaged in Zend Server
 • Young i Professionals (YiPs) site •Various levels of testing done •Install from source code • Github (PHP front-end only) • Details coming up 27
  • 28. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Zend Server for IBM i • Download Zend Server 8.x • http://www.zend.com/en/products/server/downloads-ibmi • Easy upgrade from 6.x • Includes latest approved toolkit • Requires IBM i 6.1 and up
 
 
 
 
 • Editions • http://www.zend.com/en/products/server/editions • Basic (free), Professional, Enterprise • Same download, different license 28
  • 29. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Get current PTFs within your release •Latest DB2 for IBM i group PTF level for your release § 6.1: WRKPTFGRP SF99601 § 7.1: WRKPTFGRP SF99701 § 7.2: WRKPTFGRP SF99702 § For the latest levels: 
 http://www-947.ibm.com/systems/support/i/fixes/
 and click Group PTFs 29
  • 30. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting New versions on YiPs • Young i Professionals (YiPs) site •http://youngiprofessionals.com/wiki/XMLSERVICE •Install from source code •Two parts: RPG and PHP • Installation instructions are on the site 30
  • 31. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting “Bleeding edge” also on YiPs • Test versions of XMLSERVICE § “For brave and helpful only” § Rapid releases to resolve issues or add functionality § http://174.79.32.155/wiki/index.php/XMLSERVICE/XMLSERVICETesting • Look under
 “Active test versions” 31
  • 32. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting YiPs installation location • Choose XMLSERVICE installation library •CRTXML compiles into XMLSERVICE test library • If use test library, configure with toolkit.ini’s “XMLServiceLib” •CRTXML2 compiles into ZENDSVR production library •CRTXML6 compiles into ZENDSVR6 production library • Standard directory for PHP toolkit code •/usr/local/zendsvr(6)/share/ToolkitApi •“zendsvr6” for Zend Server 6.x 32
  • 33. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting GitHub is latest home to the toolkit • Front-end PHP part of toolkit is now managed on Github • Community can enter issues, submit pull requests, add examples • Composer and Packagist…getting close! • https://github.com/zendtech/IbmiToolkit 33
  • 34. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Verify installation: run demo scripts § Deploy the sample scripts: • http://files.zend.com/help/Zend-Server-IBMi/content/ i5_installing_sample_scripts_ibmi.htm 34
  • 35. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Program calls 35
  • 36. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Calling demo script with result Call_program_RPG.html Click “Call program” to pass parameter to PHP and then RPG 36
  • 37. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting RPG program from ZENDSVR samples File: ZENDSVR/QRPGLESRC Member: COMMONPGM C *ENTRY PLIST C PARM CODE 10 C PARM NAME 10 ****************************************************** C CODE IFEQ '1' C movel 'IBM' name C ELSE C CODE IFEQ '2' C movel 'Zend' name C ELSE C movel 'wrong code' name C ENDIF C ENDIF C* C SETON LR C RETURN 37
  • 38. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting PHP to call it /www/zendsvr/htdocs/Samples/Toolkit/Call_RPG_example.php Call_RPG_example.php 38
  • 39. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting AddParameterChar in detail AddParameterChar() is defined in ToolkitService.php I / O Le ng th C o m m en t V ar n a m e Ini t va l function AddParameterChar(
 $io, $size, $comment, $varName = '', $value, $varying, $dimension) Our example: 39
  • 40. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting More parameter types AddParameterChar($io, $size, $comment, $varName, $value, $varying, $dimension) AddParameterInt16($io, $comment, $varName, $value, $dimension) [5i0 ints] AddParameterInt32($io, $comment, $varName, $value, $dimension) [10i0 ints] 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) 40
  • 41. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Additional program call features •PCML parameter definitions (optional) •Complex data structures •Arrays and output counter fields •Service programs, procedures, return values 41
  • 42. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Common question •“My RPG data structures are complex. Is there a shortcut to creating the PHP parameters?” •“I am a PHP developer. I don’t understand the RPG data types. My RPG programmer doesn’t know how to explain.”
 •The solution is here! 42
  • 43. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting New RPG-to-PHP parameter mapping tool •http://yips.idevcloud.com/Samples/DSpecTool/ •Creates PHP code based on D Specs •Open source: https://bitbucket.org/inext/xmlservice-rpg 43
  • 44. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Paste the RPG code 44
  • 45. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Voila…parameters in PHP 45 •Creates perfect parameters, including any procedure name •You may have to adjust the order for data structures
  • 46. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Commands 46
  • 47. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Several ways to call commands $conn->CLCommand(‘my command’); $conn->CLInteractiveCommand(‘DSP.... command’); $conn->CLCommandWithOutput(‘RTV... command’); Details ahead... 47
  • 48. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Simple command // CLCommand to add library list entry $cmdString = ‘ADDLIBLE LIB(ALANLIB)’; $success = $conn->CLCommand($cmdString); if($success) { echo ‘Added library’; } else { echo ‘Error: ’ . $conn->getErrorMsg(); } 48
  • 49. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Interactive command output $cmdString = ‘DSPLIBL’; // CLInteractiveCommand returns “screen” results $liblArray = $conn->CLInteractiveCommand ($cmdString); if($liblArray) { // output full result of DSPLIBL command in an array // <pre> </pre> formats the array echo '<PRE>' . print_r($liblArray, true) . '</PRE>'; } Results on next slide... 49
  • 50. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Results of DSPLIBL Array ( [0] => 5770SS1 V7R1M0 100423 Library List 3/19/12 8:52:44 Page 1 [1] => ASP [2] => Library Type Device Text Description [3] => QSYS SYS System Library [4] => QSYS2 SYS System Library for CPI's [5] => QHLPSYS SYS [6] => QUSRSYS SYS System Library for Users [7] => DBU80 SYS [8] => QSYS38 SYS [9] => DC@EPC03 USR EPC-814 DC@ADKPGM [10] => ZENDSVR USR [11] => QGPL USR General Purpose Library [12] => QTEMP USR [13] => * * * * * E N D O F L I S T I N G * * * * * ) 50
  • 51. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Get info with RTV* commands CLCommandWithOutput() gets output from RTVJOBA, RTVOBJD, RTVUSRPRF... public function getJobAttributes() { // Note: specify (?N) for numeric attributes $cmdString = 'RTVJOBA JOB(?) USER(?) NBR(?) CURUSER(?) SYSLIBL(?) CURLIB(?) USRLIBL(?) LANGID(?) CNTRYID(?) CCSID(?N) DFTCCSID(?N)';
 // Send command; get output array of key/value pairs $outputArray = $this->ClCommandWithOutput($cmdString);
 return $outputArray; } //(public function getJobAttributes()) $attrs = $conn->getJobAttributes(); // run command echo ‘<pre>’ . print_r($attrs, true) . ‘</pre>’; // print_r() formats arrays Results on next slide... 51
  • 52. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Output from RTVJOBA Array of job attributes Array(
 [JOB] => QSQSRVR
 [USER] => QUSER
 [NBR] => 240164
 [CURUSER] => QTMHHTTP
 [SYSLIBL] => QSYS QSYS2 QUSRSYS [CURLIB] => *NONE
 [USRLIBL] => QTEMP QGPL MYUTIL
 [LANGID] => ENU
 [CNTRYID] => US
 [CCSID] => 37
 [DFTCCSID] => 37 ) 52
  • 53. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 More examples 53
  • 54. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting List of output queues 54 // includes ToolkitService.php as well require_once('iToolkitService.php'); // connect to toolkit $conn = ToolkitService::getInstance('*LOCAL', '', ''); $conn->setOptions(array('stateless' => true)); // instantiate our object-finder object. $objectList = new ObjectLists($conn); // getObjectList returns an array. Each element is a 30-char string. // 10 chars for object name; 10 for library; 10 for type. $outqItems = $objectList->getObjectList('*ALL', '*ALL', '*OUTQ'); // Parse the name and library. $outqNameLibs = array(); foreach ($outqItems as $outqItem) { $nameAndLib['name'] = substr($outqItem, 0, 10); $nameAndLib['lib'] = substr($outqItem, 10, 10); $outqNameLibs[] = $nameAndLib; } //(foreach ($outqItems as $outqItem))
  • 55. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Output queue display 55 by var_dump’ing $outqNameLibs
  • 56. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Array of data structures 56 •See example here: http://forums.zend.com/viewtopic.php? f=113&t=105248 •Important snippets here: // Subfields for data structure // Here's a character field array, size 3, that's part of the DS $ds[] = $conn->AddParameterChar('both', 21,'Part', 'PTPRT', ‘’) ->setParamDimension(3); // three records // DSCOUNT is a counter field. Value is set by RPG/COBOL program. Value will control the number of MULTDS fields that return (see data structure MULTDS below) $param[] = $conn->AddParameterZoned('both', 5, 0, 'how many MULTDS array elements actually return', 'DSCOUNT', 6)->setParamLabelCounter('DSCOUNT'); // Multi-occurrence data structure with maximum dimension set to 100 but whose final output count will be determined by DSCOUNT. field names arbitrary. Name them whatever you wish $param[] = $conn->AddDataStruct($ds, 'MULTDS') ->setParamDimension(100) // max of 100 records ->setParamLabelCounted('DSCOUNT');
  • 57. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Read a data area 57 require_once(‘iToolkitService.php’); // set up name of data area $dataAreaObj = new DataArea($ToolkitServiceObj); $dataAreaObj->setDataAreaName('MYLIB', 'MYDTAARA'); // read it $value = $dataAreaObj->readDataArea(1, '*ALL'); // offset and length // output string value from data area echo $value;
  • 58. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Connecting 58
  • 59. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Basic connection • Connect with database, user, password • Try *LOCAL or real database name • WRKRDBDIRE shows valid names • If leave blank (‘’, ‘’, ‘’): connect with default web user • QTMHHTTP
 59 <?php // bring in the toolkit require_once('ToolkitService.php'); // connect to local IBM i $conn = ToolkitService::getInstance('*LOCAL', 'MYUSER', ‘MYPASS’);
 // specify stateless mode (simple: no internal key needed) $conn->setOptions(array('stateless'=>true));
  • 60. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Choice of stateless or stateful (private) • Easiest way to start: stateless § Quicker initial connection, runs tookit directly in DB2 job (QSQSRVR job) § No guarantee that you’ll get same job from pool § Share QTEMP between SQL and RPG (runs in DB2 job) § Specify ‘stateless’ $conn=>setOptions(array(‘stateless’=>true)); • Advanced: stateful/private § A new job is started and “reserved” for re-use § Retains file cursors (READE position), QTEMP, LIBL, open file handles § Best performance when many program calls § Specify ‘InternalKey’ as unique job identifier $conn=>setOptions(array(‘InternalKey=>‘/tmp/jim123’));
 60
  • 61. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Safety first 61
  • 62. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Prevent RPG/COBOL errors from hanging • “Message waiting” Inquiry messages are to be avoided • It seems “normal” for errors to pop up in a green screen • “Record lock,” “Add more records to file?” “Level check” • Find them with DSPMSG MSGQ(QSYSOPR) MSGTYPE(*INQ) • If an RPG/CL does not complete, it won’t return control • Web page will “hang” till it times out or operator ends job • If operator ends job, further requests may go nowhere • Three techniques coming up—aside from not allowing faulty programs in production 62
  • 63. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 1. Wrap program in CL having MONMSG • Wrap RPG/COBOL call in a CL (control language) program containing a MONMSG statement. Example: PGM PARM(&PGMNAME &ERRORFL) DCL &PGMNAME *CHAR 10 DCL &ERRORFL *CHAR 1 /* if any error, end and return error code ‘1’ */ CALL PGM(&PGMNAME) MONMSG CPF0000 EXEC(GOTO $ERROR) CHGVAR &ERRORFL '0' RETURN $ERROR: CHGVAR &ERRORFL '1' ENDPGM 63
  • 64. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 2. Toolkit timeout technique // give RPG/COBOL 15 seconds to complete before we give up and end the program, so that PHP doesn't 'hang'. $options = array('stateless' => true, 'customControl' => '*call(15/kill/server)'); $conn->setOptions(array($options)); 64
  • 65. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 3. Set a global reply via System reply list • CHGJOB INQMSGRPY(*SYSRPYL) • WRKRPYLE, ADDRPYLE 65
  • 66. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Resources, events, Q&A 66
  • 67. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Resources • Alan’s toolkit page with links to other resources • http://alanseiden.com/toolkit
 • Young i Professionals site • http://youngiprofessionals.com/wiki/XMLSERVICE
 • Zend Toolkit Forum • http://forums.zend.com/viewforum.php?f=113 • “PHP on IBM i”->”Zend Server for IBM i”->”New Toolkit” • Zend toolkit manual • http://files.zend.com/help/Zend-Server-IBMi/zend- server.htm#php_toolkit_xml_service_functions.htm • Github site • https://github.com/zendtech/IbmiToolkit 67
  • 68. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Try the toolkit and get to web/mobile 68
  • 69. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting A community resource: get involved • Help us enhance the toolkit § Report any issues on the Forum
 • Contribute enhancements, tips, fixes § Write to forum or alan@alanseiden.com • Why? § Make the toolkit and IBM i platform better for everyone § Sharpen your skills; work with great people J § Working with open source demonstrates commitment to your chosen platform and your career as a whole 69
  • 70. alanseiden.com Alan Seiden Consulting PHP Toolkit for IBM i technical details
  • 71. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting To check XMLSERVICE version call qp2term qsh -c /qsys.lib/zendsvr6.lib/xmlver.pgm returns something like: XML Toolkit 1.9.1$ Make sure it’s at least 1.8.5. Critical bug was fixed in 1.8.0. (If the “xmlver” program not found, your XMLSERVICE is too old!) 71
  • 72. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting How to use persistent DB2 connection • See “DB2 and PHP Best Practices on IBM i” • Persistent DB connection § $conn = ToolkitService::getInstance(‘*LOCAL’, ‘myuser’, ‘mypw’, ‘’, true); § Fifth param is persistence flag § Or re-use an existing DB2 persistent connection // connect to db. Make sure i5 naming mode matches between DB2 and toolkit $namingMode = DB2_I5_NAMING_ON; // ON or OFF $db = db2_pconnect('DBNAME', 'user', 'pass', array('i5_naming' => $namingMode)); // Connect to Zend API, passing db resource and i5 naming mode instead of dbname/ user/password. $conn = ToolkitService::getInstance($db, $namingMode); 72
  • 73. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Useful settings in toolkit.ini • Located in /usr/local/zendsvr(6)/share/ToolkitApi • Useful settings: •[system] • Debug=true • Creates debug.log • XMLServiceLib = "ZENDSVR6“ • Or = “XMLSERVICE” • Lets you try new versions safely 73
  • 74. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting How to check or set CCSID • DSPSYSVAL QCCSID •If not 65535, you’re probably OK •Change with CHGSYSVAL SYSVAL(QCCSID) VALUE(xyz) • or in Apache config: /www/zendsvr(6)/conf/httpd.conf •USA settings: • DefaultFsCCSID 37
 CGIJobCCSID 37 •Different outside of USA. Check list of “Job CCSID”: • http://www-03.ibm.com/systems/i/software/globalization/default_list.html 
 • Everyone must set a CCSID •This really means YOU.....otherwise toolkit will not work •I mean it J • P.S. Please set your CCSID 74
  • 75. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Connect from
 “off the box” 75
  • 76. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 2-tier = Run PHP on Windows/Linux/Mac • A common developer request • Develop on laptop § Connect to XMLSERVICE on IBM i; then deploy PHP code to IBM i with no code changes • Or run production PHP on non-i machine, calling IBM i- based RPG, commands, etc. • Never a charge or cost for this 2-tier support § All free and open source 76
  • 77. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Alternatives for 2-tier transports • DB2 Connect and ODBC § “DB2 Connect” software from IBM (paid software) • Advantage: handles SQL queries, too, as if they were local to PC § No-charge alternative: ODBC (free with IBM i Access) • Other alternatives § CGI/HTTP (no drivers needed) § Many more are possible because XML can be sent over any type of connection 77
  • 78. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Connect via ODBC • First, set up ODBC database config on your PC § Connection name will be used as the db name (*LOCAL is not allowed) § Documentation: http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/ index.jsp?topic=%2Frzaii%2Frzaiiodbc04.htm • New API style connection $conn = ToolkitService::getInstance(‘MYODBCCONN’, ‘myuser’, ‘mypw’, ‘odbc’); • CW style connection § Specify database name in toolkit.ini [hosts] myibmi = MYODBCCONN 
 // PHP to connect via ODBC $options = array(CW_TRANSPORT_TYPE=>’odbc’); $conn = i5_connect(‘myibmi’, ‘myuser’, ‘mypw’, $options); 78
  • 79. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting HTTP transport • HTTP/CGI interface, no drivers needed (1.5.0+) • Not enabled by default (secure) § See http://www.youngiprofessionals.com/wiki/XMLSERVICE § “Optional XMLSERVICE REST interface via RPG CGI (xmlcgi.pgm)” • Point to it with toolkit.ini 79 [transport] ; transport type allows configuration of transport from this INI. transportType = "http" ; ibm_db2 is default. Other choices: "odbc", "http" ; for http transport only httpTransportUrl = "http://example.com/cgi-bin/xmlcgi.pgm" ; default plug size (expected output size): 4K, 32K, 512K (default), 65K, 512K, 1M, 5M, 10M, 15M ; can also change in code with $conn->setOptions(array('plugSize' => '4K')); or desired size
  • 80. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Performance “do”s and “don’t”s 80
  • 81. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Performance “don’t”s • Don’t use disconnect() unless it’s the end of the day, logout, etc. • Reconnection in stateful mode is slow • Official samples set a bad example here • Don’t allow inquiry messages to arise, hanging your job (and maybe more) • See MONMSG and related topics to prevent this • Don’t run commands or programs that might return an error to the toolkit • Example: ADDLIBLE can return “already exists” error. Prefer CHGLIBL or other technique • Toolkit will fetch joblog for error reporting, which can be slow • Not XMLSERVICE’s fault…in future we may allow “fast” (no joblog) mode sometimes for non-critical errors 81
  • 82. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Performance “do”s • Do use the proper connection option • Stateless: usually simplest and best. No new jobs needed • Stateful (InternalKey): requires care in choosing IPC key, and not disconnecting too often • Do set plugSize as small as possible for the expected data • $conn->setOptions(array(‘plugSize’=>’4K’)); // minimum • Others are 32K, 512K, 65K, 512K, 1M, 5M, 10M, 15M • Do use a persistent db2 connection that you share with the toolkit • See previous slide: “How to use persistent DB2 connection” • Do combine multiple command and program calls in a single CL program, then call the CL from the toolkit • Also wrap “RTV*” commands in CL 82
  • 83. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Troubleshooting 83
  • 84. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Retrieve error code and message • getErrorCode(), getErrorMsg() • These will return a CFP-type code and descriptive message obtained from the joblog
 echo 'Problem calling program. Code: ’ . $conn->getErrorCode() . '. Text: ' . $conn->getErrorMsg(); Problem calling program. Code: RNX1216 Text: Error message CPF4103 appeared during OPEN for file MNG111FM 84
  • 85. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Troubleshooting tips • Get latest toolkit version § Start with Zend Server download site § or latest XMLSERVICE and PHP wrapper • http://www.youngiprofessionals.com/wiki/XMLSERVICE § Test in XMLSERVICE library if unsure
 • Use Z-Ray § View returned XML including joblog if an error occurred
 • Create debug log § In toolkit.ini, set debug=true, then run script again • Creates /usr/local/zendsvr6/share/toolkitapi/debug.log • debug.log contains all XML send/received, connection info • Tip: to split into daily logs, specify:
 $conn->setOptions(array('debug'=>true, 'debugLogFile' =>'/usr/ local/zendsvr6/var/log/toolkit_debug' . date("Ymd") . '.log')); 85
  • 86. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Z-Ray will speed development • Shows every query and time for each query • Toolkit extension for Z-Ray shows each program call, input/output, timing • Save time otherwise spent hunting in debug logs! 86
  • 87. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Interactively debug RPG or COBOL program 1. Add the following line to your PHP script before the program call to be debugged. $toolkitConn should be your toolkit connection object. $toolkitConn->setOptions(array(‘customControl'=>'*debug')); Run your script. The script will "hang" while it waits on #2 below...(move to green screen 5250 for steps 2-10) 2. A MSGW inquiry message in DSPMSG QSYSOPR will be generated by the toolkit. 3. Note the job information (number, name, user) provided in the MSGW. 4. STRSRVJOB using that job information as parameters. 5. STRDBG with the program and library you wish to debug. 6. Answer the MSGW. Any answer will do--"G" is fine. 7. The RPG program source will appear in debug mode in your terminal, ready to step through, allowing you to inspect variables, etc. 8. When done inspecting and stepping, let the RPG program complete (using function keys indicated on screen). 9. ENDDBG 10. ENDSRVJOB 87
  • 88. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting 
 Future of toolkit 88
  • 89. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting The latest • PHP toolkit version 1.6.1 / XMLSERVICE 1.9.2 § Faster § Experimental “fetch data via recordset” so that plugSize may not be needed in future • Future § Always faster and faster § Further improvements for ease of use § Samples on GitHub Full list of current improvements: http://174.79.32.155/wiki/index.php/XMLSERVICE/XMLSERVICEChangeLog
 http://174.79.32.155/wiki/index.php/XMLSERVICE/CWChangeLog
 89
  • 90. PHP Toolkit from Zend and IBM: Open Source on IBM iAlan Seiden Consulting Contact and get tips Alan Seiden Alan Seiden Consulting Ho-Ho-Kus, NJ 90 alan@alanseiden.com ● 201-447-2437 ● twitter: @alanseiden Free PHP tips: 
 http://alanseiden.com/tips