the zen of using php without zend server...w php can be called from cl and rpg too! w often software...
TRANSCRIPT
The Zen of PHP without Zend Server AlanSeidenRichardSchoen
Principal,SeidenGroupMentorsCIOs&developmentteamsDelivermoderntechnicalsolutions
OpenSourceAdvocateCo-developerofPHPToolkitforIBMiFounderofClubSeidencommunity
Host/Sponsor,CIOSummit
Alan Seiden
Owner,MobiGoGoFormerowner,RJSSoftwareSystemsInnovatorinIBMisolutions(30+years)MemberofSeidenGroupSrSolutionsConsultant-Pegasystems
BuilderDeveloperofiForgitIBMigitclientIBMi,Windows,LinuxDeveloperMobileAppDeveloperRPG,CL,C#,VB,Node,PHP,Python,Java,HTML,CSS,etc.
Richard Schoen
DevelopwebandmobileapplicationsSupportCommunityPHP
TroubleshootthetoughestissuesTraindevelopersinopensource&IBMi
PHPAPIsGit
Node.jsDb2Python
Open Source Experts
seidengroup.com
Why PHP?
w PHPhasbeenpivotalinbringingwebapplicationstoIBMi
w Opensourceapplications:CMSes,eCommercew MantisBugTrackerwasanoldiebutgoodie
w Award-winningapplicationsacrossallindustriesw ContinuetoaccessyourDb2data,RPGcode,andmorew PHPToolkithelpedcompatibilityandintegrationw WebservicesandAPIs
w FirsttasteofcallingexternalAPIsfromIBMiw Creditcardpayments… Salesforce…manymore
w Convertinggreenscreenstoweb
w Communityandconferencesites
w Blogsw Wordpress..beyondblogs..StarWarssite,
more!
Web apps and APIs
w PHPcanbecalledfromCLandRPGtoo!w Oftensoftwaredevelopmentkits(SDKs)werewritteninPHPw Easytogetstartedw StillcontrolflowfromtraditionalRPGw UsenewPHPpowertoaccessAPIsandotherfunctionality,create
spreadsheets,graphics,etc.
w PHPhasalwayscontainedallthebasicstoservewebpagesandaccessAPIsw SOAPinthebeginning,RESTnow
w Millionsofusers;presentonallwebhosts
w HelpedmaketheIBMimoremainstream
Use PHP from RPG, CL, etc.
w 2004:AlanneededPHPoni5!w i5php.net—RobWard’ssitew IncludedODBCbutwasmissingmail()function!
w 2006:ZendCore—IBMshippedinitsDVDsw ZendPlatformpaidadd-on
w 2008-9ZendServerw No-costOSS+adminpages+paidadd-onsbundledw Basic/Professional/Enterpriselicenses
w 2019:CommunityPHPw RPM-basedw IncludesODBCagain
PHP on IBM i timeline
w ZendServerBasiclicensewithdrawnbyJune2021
w PHPiswidespreadonIBMi
w Ano-chargeoptionisstillneeded
w RPM-basedPHPtotherescue!w LaunchedbyIBMandZend(Perforce)w Canbeadapted/enhancedw Itworkswell
w StillanoptiontopayforZendServerProfessionalandEnterprise
w GiveRPMsatryforlicense-freePHP
PHP in 2020-2021
Why RPM your PHP?
w Minutesinsteadofhours
w NolaboriousFTP’ing,unzipping,SAVF,nohours-longinstallation
w Industry-standardYumcommandw SameasotherIBMiopensourcethesedaysw Under/QOpenSysw The“coolkids”likeit!
w Quickupgrades,toow Yum update
w Gainevenmorespeedbyautomating/scriptingtheinstallation
Quick installation
w ChooseApacheornginx
w YourexistingApacheandFastCGIconfigsstillwork!
w Multiplewebserverinstancesfordifferentworkloads
w TestinparallelwithexistingZendServer
w Couldinstallmultipleversionsviachroot
Flexible installation
w RPMPHPis64-bit,whileZendServerisstill32-bitw (asofMay2020)
w Whatdoesthatmean?
w Moredatawithouterrors(nomorememorydumperrors)
w Good-bye,“LDR_CNTRL”memoryhack!
More bits = more data!
w PHP7wasalreadyfast
w PHP7withRPMsisevenfasterw ACPUtypebenchmarktestIranshowed0.11secondsinsteadofZendServer0.31seconds
w Thatwasn’tarealisticdatabase-typetest,butwasagreatstart!
w Lighterdistributionisquickertostartup,toow EspeciallyPHP-CLIcalledfromCL,RPG,etc.
Improved performance
w AlthoughCommunityPHPismissingsomeoftheextensionsthatwerebundledinZendServer….
w “Wecanrebuildthem!”
w Severalpopularonesw Ibm_db2w Ldapw Imagemagickw Implementingmail()withsendmail
w IBMhasdoneagreatjobinbuildinginfrastructuretoletusaddtheextensionswewantandneed
This PHP is open and flexible
On PHP 7 Yet?
w SpurredbycompetitionwithFacebook’s“Hack”
w Noticeablespeeduponlargesites—pages“pop”
PHP 7’s Faster than PHP 5.x
w Newfeatures:w https://www.php.net/manual/en/migration70.new-features.php
w Codechangesrequired?Long-deprecatedfunctionsremovedw https://wiki.php.net/rfc/remove_deprecated_functionality_in_php7w OldMySQLcodeusingthemysql_*functionsshouldbeupdatedtomysqli_*(“IMySQLImproved”)orPDO
w Oldregularexpressionsyntax“ereg()”wasremovedw https://www.scriptarticle.com/function-ereg-is-deprecated-in-php-5-3-x/
What else about PHP 7?
w Yourcodeshould“justwork”withafewexceptionsw https://www.seidengroup.com/2017/07/24/resources-for-upgrading-to-php-7-on-ibm-i/
w RPMupgradetoPHP7isthesameexceptusethepath/QOpenSys/pkgs/bin/php
w Check/usr/local/zendsvr6/var/log/php.logfordeprecationnoticesw Testyourcodewithhttps://github.com/Alexia/php7mar
w PHP7canruninparallelwitholderversionssuchasPHP5.6w (IfyoufindPHP6,letusknow!J)
Upgrading from PHP 5.6 to PHP 7
Simple Speed Test Script (SSTS) <?php
// homemade profiler using microtime(true), current time in seconds
$start = microtime( true );
for ($i=0 ; $i<1000000 ; $i++) {
serialize($i);
}
$end = microtime( true );
$duration = $end - $start;
echo "Took " . $duration . " seconds.\n";
PHP 5.6 vs 7.3 $start = microtime( true );
for ($i=0 ; $i<1000000 ; $i++) {
serialize($i);
}
$end = microtime( true );
$duration = $end - $start;
echo "Took " . $duration . " seconds.\n";
RunfromCALLQP2TERMorSSHterminalcd /www/myserver/htdocs [location of speedtest.php]
1. /usr/local/zendsvr6/bin/php –n speedtest.php “Took 0.37887215614319 seconds.” (PHP 5.6.18)
2. /usr/local/zendphp7/bin/php –n speedtest.php “Took 0.30699110031128 seconds.” (PHP 7.3.11)
3. /QOpenSys/pkgs/bin/php –n speedtest.php “Took [really short/quick time; but it’s a narrow, made-up benchmark] seconds” (PHP 7.3.17)
Let’s Install PHP!
w ToinstallCommunityPHPwithODBC,weliketheseinstructionsfromKingHarrison(K3S):w https://odbcphp.k3s.com/
w WerecommendSSHtogetintoPASEw STRTCPSVR*SSHDw Industry-standard:youryoungerdeveloperswillthankyou(installthebashshellforthem!)w (Inbash,theup-arrowkeyworkslikeF9tobringbackpriorcommands)
w OpensourcesoftwareworksbetterinSSHthaninQP2TERMorQSH
Install PHP using Yum
w FollowtheK3SinstructionstomakesureYumandtheOpenSourcePackageManagementwindowofACSaresetupw https://www.ibm.com/support/pages/getting-started-open-source-package-management-ibm-i-acs
w AddtheCommunityPHPrepositorytoyourIBMi’sYum/RPMenvironmentw yum-config-manager--add-repohttp://repos.zend.com/ibmiphp/w (Orothernon-IBMrepoyouneedtoadd)w Youcouldevencreateyourownrepositoryw Forexample,wemaintainourown“repos”containingadditionalRPM-
basedmodules
Getting Yum ready
Open Source Package Management
w IBMisshserverservicemustberunningonport22
Open Source Package Management (ACS)
w LoginwithaQSECOFRor*ALLOBJleveluser
Open Source Package Management
w Youmayreceivetheseprompts.JustsayYes!
Open Source Package Management
w Allisworkingifyouseelistofpackages!
w Theyumcommand:w Yum install php-* w TIP:Youruserprofilemusthave*ALLOBJtoinstallviaYum
w MorefromtheK3Ssetupdocumentw SetupApacheorNginxwebserverw YoucancontinuetouseyourexistingApacheinstancesthatZendServer
createdw SetupODBCforDb2accessrunningonIBMiw HowtouseODBCtoconnectfromaLinuxorWindowscomputertotheIBMiaswell!
w TipsforusingthePHPToolkit(XMLSERVICE)
Install PHP using Yum (continued)
w FastCGIprestartsPHPjobstohandlewebworkloads
w Minimalcontentsoffastcgi.conf(in/www/myserver/conf/):w Server type="application/x-httpd-php" CommandLine="/QOpenSys/pkgs/bin/php-cgi" StartProcesses="1"
w Additional/optionalkeystoincludeinfastcgi.conf:w HowmanyPHPjobstostartw SetEnv="PHP_FCGI_CHILDREN=20"
w Howlongtowaitbeforea408timeoutw RequestTimeout="60"
FastCGI configuration
# fastcgi.conf Server type="application/x-httpd-php" CommandLine="/QopenSys/pkgs/bin/php-cgi" StartProcesses="1" SetEnv="LIBPATH=/QOpenSys/pkgs/lib" SetEnv="PHPRC=/QOpenSys/etc/" SetEnv="PHP_FCGI_CHILDREN=20" SetEnv="PHP_FCGI_MAX_REQUESTS=0" ConnectionTimeout="30" RequestTimeout="60" SetEnv="CCSID=1208" SetEnv="LANG=C”
w PHP_FCGI_CHILDRENw MaxnumberofPHPjobsneededatonetimew Defaultof10islow.Try20,30,40,50,andtest.w WerunamonitortotrackhowmanyPHPjobsareusedatatime.
w RequestTimeoutw SecondsbeforeFastCGIreturnsanHTTP408errorw Considersettingupmultiplewebserverinstancestohandlevaryingworkloads(slowvs.fast)
Enabling and optimizing FastCGI—Details
w nginxwebserverw FlexiblewebserveralternativetoApachew Fullopensource--notcoveredbySWMAasApacheis,butyoucouldbuyIBMTSSsupportifneeded
w Allowsautomatedsetup,includingofSSL(noDCM)w NginxworkswellwithalternateFastCGIcalledphp-fpm
w Php.inisettingsw EditdirectlyinthePhp.inifileusingEDTForyourfavoriteeditororvimJ
w date.timezonew https://www.php.net/manual/en/timezones.phpw date.timezone = America/New_York
Other options
ODBC is Back!
History of Open Source Connectivity
w Before,IBMbuiltcustommiddlewareforeachlangfortheCLI.ProwascouldcustomizeforIBMiandDb2.ProblemsinCLIthough.
w Db2ConnectproductallowedsamecodeLUWandIBMi.“WanttocodeonPC/laptopandthenrunonIBMi.”LocaldebuggingwithfavoriteIDE.Twoversionsofcode:ODBCfreeorpay/configDb2Connect.
w Opensourceontheriseandtotherescue,unixODBCdriver.WasonWindowsandLinuxbutnotIBMi.Neededdb2driverunderneaththatworkedinPASE.
w NOWODBConIBMi.MakingIBMiworkasmainstreamaspossible.Genericconnector!Don’tneedtocreatespecialversionsanymore.w FrameworksthathaveODBCcanworknow.w YoumaydeveloponPC,thendeploytoIBMi
ODBC Architecture IBMi
IBMiDB2Database
unixODBCDriverManager
IBMiAccessODBCDriver
OPM/ILEAppsRPG,CL,COBOL
PASEApps
PHP,Python,Node
RemoteIBMiDB2Database
Windows,Linux,MacandnativeIBMiDeveloperscanuseexactsamecodebasewithnochanges
Install ODBC Yum Package Prerequisites
w Installyum
w Installwget
w Installrpminstalled
w InstallunixODC
w InstallunixODBC-devel
w WewilluserpmcommandwhenweinstalltheIBMiAccessODBCdriver
Download IBM i PASE ODBC Driver
w IBMiAccessClientSolutionsSite:https://www.ibm.com/support/pages/ibm-i-access-client-solutions**Note:YouwillneedanIBMaccounttologinanddownload
Download IBM i PASE ODBC Driver
Upload IBM i Access PASE ODBC Driver
w Unzipibm-iaccess-1.1.0.xx-0.ibmi7.2.ppc64.rpmfromIBMiAccess_v1r1_PASE_AP.zip
w Uploadibm-iaccess-1.1.0.xx-0.ibmi7.2.ppc64.rpmtoIFSrootdiras:/ibm-iaccess-1.1.0.xx-0.ibmi7.2.ppc64.rpmusingyourfavoritefiletransfertool.
w Note:“xx”aboveisfileversionnumberinyourdownload.AsofMay2020,itwas“14”.
Install IBM i Access PASE ODBC Driver
w StartQshell(STRQSH),PASE(CALLQP2TERM)or(BEST)sshterminalsessionusingputty,MobaXterm,MacTerminal,orothersshterminalclient
w RuncommandlistbelowtoinstalltheIBMiAccessODBCdriver
w cd/PATH=/QOpenSys/pkgs/binexportPATH
rpm-iibm-iaccess-1.1.0.xx-0.ibmi7.2.ppc64.rpm
w Onceinstallhascompletedyouwillbenotifiedonthecommandline.
Check for Default ODBC Data Source
w Fromyourterminal(again,SSHisbest)
w RuncommandlistbelowtolisttheIBMiAccessODBCdriverdefaultsfromodbc.ini
w cd/QOpenSys/etc
catodbc.ini
w Catcommanddisplayscontentsofodbc.ini
Check for Default ODBC Data Source
w Contentsofdefaultodbc.inifile
w YoushouldbeabletoconnecttootherIBMisystems
w ChangelocalhosttoothersystemhostnameorIPaddress
w UsePassword
Potential PTFs Needed
w PTFneededfor*CURRENTusertoworkwithoutpasswordw 7.2:SI68113w 7.3:SI69058w 7.4:(noneneeded;comeswiththeoperatingsystem)
w *CURRENTonlyworksonlocalhostsystem(samepartitionasyourcode)
First ODBC Connections
isql command line
w TypeisqlandpressEnter
w Showscommandlineoptions
w Optiondetails:w https://www.mankier.com/1/isql
Connecting to DB2 via ODBC
w Type:isql*LOCAL–vandpressEnter
Running a Query Test
w Type:select*fromqiws.qcustcdtandpressEnter
w Whendone,typequitandpressEntertoexitisql
Your PHP on ODBC
<?php
$connection = odbc_connect('*LOCAL', '', ’');
$stmt = odbc_exec($connection, 'select * from QIWS.QCUSTCDT');
while ($row = odbc_fetch_array($stmt)) {
print_r($row);
}
It works! <?php
$connection = odbc_connect('*LOCAL', '', ’');
$stmt = odbc_exec($connection, 'select * from QIWS.QCUSTCDT');
while ($row = odbc_fetch_array($stmt)) {
print_r($row);
}
Optimizing ODBC
w PrestartjobsnamedQZDASOINITruninQUSRWRK
w Checkoutcurrentconfiguration:w DSPSBSDSBSD(qusrwrk)w Thenchoose10,Prestartjobentriesw Type5nexttoQZDASOINIT
w Defaultsareverylow.w Initialjobs=1,threshold=1,adljobs=2
w Configureasneeded:CHGPJE SBSD(QSYS/QUSRWRK) PGM(QSYS/QZDASOINIT) STRJOBS(*YES) INLJOBS(xx) THRESHOLD(xx) ADLJOBS(xx)
Configure ODBC Prestart Jobs
w DSPACTPJSBS(QSYSWRK)PGM(QSQSRVR)[ibm_db2]
w DSPACTPJSBS(QUSRWRK)PGM(QZDASOINIT)[odbc]
Display Prestart Job Usage Statistics
Choose an IDE
w Eclipse-basedIDEsw NetBeansw https://netbeans.org
w ZendStudiow https://store.zend.com/zend-studio-for-ibm-i-basicw (formerlyfreeforIBMi,nowpaid)
w MicrosoftVisualStudioandVSCodew https://code.visualstudio.com/docs/languages/phpw TIP:InstallSSHplugin(https://code.visualstudio.com/docs/remote/ssh)
w PHPStorm(https://www.jetbrains.com/phpstorm)w Paidproductforpowerusers(Seidendevelopers’fave)
Editors, editors, editors! And more!
Debugging techniques
w Var_dump()anderror_log()aregreatbutlimited
w Xdebugw https://xdebug.org/w Industry-standardfamousPHPextensionw Single-stepdebugger,includingremotedebugging(ontheIBMi),stacktraces,andmore
w IDEdebuggersw NearlyIDEshavedebugging.Examples:w VSCode:https://marketplace.visualstudio.com/items?
itemName=felixfbecker.php-debugw PHPStormwithxdebug:https://www.jetbrains.com/help/phpstorm/
debugging-with-phpstorm-ultimate-guide.htmlw VisualStudioPHPTools
Interactive debugging with PHP
Let’s Code!
w Seewhereourimaginationstakeus!
Live coding session with Richard
Support Options
w Communitysupportoptionsw GetPHPversionupdatesfromCommunityPHPrepositoryw Ryver(https://ibmioss.ryver.com)w IBMiOSSmidrange.comlist(https://archive.midrange.com/opensource)
w Paidsupportoptions(includingbreak/fix)w Perforce(Zend)w Break/fix+extras+tools
w Seidenw Migrationhelp+break/fix+tools+repoofextensions(e.g.ibm_db2)
w IBM(TSS)w Break/fix
w Theremaybeothers–Letusknow
How is RPM PHP Supported?
AlanSeidenSeidenGroupHo-Ho-Kus,[email protected]:@alanseidenStayinTouch:seidengroup.com/tips
[email protected]://mobigogo.net
Contact | Stay in Touch