From YiPs Wiki (i powered)

XMLService: XMLSERVICE Connect

(click to open)

Quick Page Table of Contents

Scanning…

XMLSERVICE Connections

Goto Main Page
Goto Documents

You may want to refer to the DB2 connection link before reading this page PHP DB2 Connection topics.

Sometimes a real conversation helps …

Customer wants to know how to remain stateless, but get the benefit of being able to audit the use of RPG subprocedure invocations via XMLToolkit without toggling back and forth (different QSQSRVR jobs).
Stateless may use multiple QSQSRVR jobs (toggling), this is definition of ‘stateless’ in PHP fastcgi environment (working correct).

Will ToolkitService object using persistent db2 connections and “stateless => true” help single QSQ job?
Toolkit “stateless => true” via db2 transport using db2_connect or db2_pconnect makes no difference, fastcgi implies unpredictable QSQSRVR job will be used (command line slightly more predictable over web).

Why ‘unpredictable’ QSQ?
It’s all web PHP fastcgi ‘random’ worker selection, NOTHING to do with ibm_db2 ‘connection’ persistent or non-persistent, toolkit connection is irrelevant. Apache web site using fastcgi routes “randomly” to any available PHP worker job php-cgi, therefore ‘random’ php-cgi worker using db2_(p)connect<>QSQSRVR will also appear ‘random’. To wit, you end up different QSQSRVR jobs (toggle back and forth). Technically, fastcgi protocol, PHP workers poll a single fastcgi socket waiting to take some work, ZS on i at /www/zendsvr6/logs/fcgi-njjjineh.sock (sock name random). As each php worker strips work off fastcgi socket (1st come == 1st do), the worker is busy communicating on ‘private web socket’ running script until finished (no longer waiting). Combination of natural web worker selection (browser ± KeepAlive), and fastcgi socket poll for work, results in ‘random’ appearance QSQ job toolkit usage, DB2 connection just came along for ride in back seat of the 1950 PHP fastcgi roadster.

Help me be one-and-only-one job?
The only way to assure private connection back to same XTOOLKIT job is ‘internalKey’=>’/tmp/XTOOLKIT_job_1′ (‘ipc’=/tmp/XTOOLKIT_job_1′).

XMLSERVICE connections discussed this page …

The jobs involved in “connections”:

1) Stateless
                    (job 1)  (job 2)                (job 3)
                    Apache   FastCGI                DB2 (stateless)      
                    -------  ---------------        ---------------------
   browser/client ->thread-->socket->php-cgi
                          --->$ctl="*here";      -->QSQSRVR+XMLSERVICE
                                                    shut down after 
                                                    each request 
                                                    ("stateless")

2) State full
                              (job 2)               (job 3)                 (job 4)
                              FastCGI               QSQ (proxy)             XMLSERVICE (state full)
                              ---------------       ---------------------   ------------------------
                          -->socket->php-cgi
                          --->$ctl="*sbmjob";
                          --->$ipc="/tmp/sally"; -->QSQSRVR+XMLSERVICE   -->XMLSERVICE
                                                                            alive until stopped
                                                                            ("state full")


Jobs originates ... 
(job 1) Apache picks any thread (1st level routing)
(job 2) FastCGI all "non-busy" worker php-cgi wait on unix domain socket /www/zend2/logs/fcgi-hmjadgek.sock (2nd level routing)
(job 3) php-cgi - database connections odbc, ibm_db2, pdo_ibm (3rd level routing)
        db2_pconnect() attach to pooled/persistent QSQ (matching profile) but leaves connection open on exit
        db2_connect() acquires a unused pre-start QSQ (or starts one) then attaches to QSQ (profile), and returns to unused pool on exit
(job 3) XMLSERVICE -- Stateless -- run inside QSQ job and clean-up after each request (3rd level routing)
        $ctl = "*here";
(job 4) XMLSERVICE -- State full -- run in separate job that any QSQ job can call using IPC (4th level routing)
        $ctl = "*sbmjob";
        $ipc = "/tmp/sally";

Drivers involved in conection:

400 server start-up Common usage Big picture Comments
STRTCPSVR SERVER(*HTTP)
  • port 80 or 10088 or … (REST/HTTP interface)
1-tier - XMLCGI CLIENT <==> IBM HTTP Server <==> XMLCGI (CLI server mode) <==> QSQxxxx <==> IBM i Resources XMLCGI + CLI from Yips (Cairns IBM Rochester)
PASE library (no start needed)
  • no port
1-tier - PHP ibm_db2+pdo_ibm+odbc (Native PASE CLI libdb400.a driver) CLIENT (PASE libdb400.a driver) <==> QSQxxx <==> IBM i Resources Native PASE CLI libdb400.a driver (IBM Rochester)
STRHOSTSVR SERVER(*DATABASE)
  • port 8471 (database)
2-tier - PHP odbc interface (IBM i Client Access odbc driver interface) CLIENT (Client Access drivers) <==> QZDAxxxx <==> IBM i Resources Client Access odbc-based drivers (IBM Rochester)
STRTCPSVR SERVER(*DDM)
  • port 446 (DDM/DRDA)
2-tier - PHP ibm_db2+pdo_ibm (DB2 Connect driver interface) CLIENT (DB2 Connect drivers) <==> QRWxxxx <==> IBM i Resources DB2 CLI DRDA-based DB2 Connect drivers (IBM Toronto)

1) Stateless — no LIBL, come/go

These connections are traditional web requests “full open/close” clean running start/stop connection to be used by any requester.

1) Stateless
   $ctl = "*here";

                    (1)           (2)           (3)
                    Apache        FastCGI       DB2 (server mode)
                    -------  ---------------    ---------------------
   browser/client -->thread--socket->php-cgi--->QSQSRVR(profile fred)
                                                XMLSERVICE (fred)      <--shut down after each request
                                            --->QSQSRVR(profile sally)
                                                XMLSERVICE (sally)     <--shut down after each request
                                            --->QSQSRVR(profile john)
                                                XMLSERVICE (john)      <--shut down after each request

Example new Toolkit (stateless):
   if ($i5persistentconnect) $conn = db2_pconnect($database,$user,$password);
   else $conn = db2_connect($database,$user,$password);
   try { $ToolkitServiceObj = ToolkitService::getInstance($conn); }
   catch (Exception $e) { die($e->getMessage()); }
   $ToolkitServiceObj->CLCommand("CHGLIBL LIBL(FREDFLIN WILMAFLIN) CURLIB(FREDFLIN)");

2) State full — LIBL, transactions, etc.

These connections are traditional 5250-like “private” connection used by one requester/task for a long period of time.

2) State full (most RPG programs)
   $ctl = "*sbmjob";
   $ipc = "/tmp/sally";
   -- or --
   $ipc = "/tmp/john";
                    (1)           (2)           (3)                       (4)
                    Apache        FastCGI       DB2 (server mode)         XMLSERVICE
                    -------  ---------------    ---------------------     ----------
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)---.->XMLSERVICE (sally) <--alive until stopped (or idle timemout)
                                            --->QSQSRVR(profile john)--. |
                  -->thread--socket->php-cgi--->QSQSRVR(profile fred)  | |
                                            --->QSQSRVR(profile sally)---.
                                            --->QSQSRVR(profile fred)  |
                                            --->QSQSRVR(profile john)--.--->XMLSERVICE (john) <--alive until stopped (or idle timemout)
Example new Toolkit (state full):
   $internalKey = '/tmp/packers';
   if ($i5persistentconnect) $conn = db2_pconnect($database,$user,$password);
   else $conn = db2_connect($database,$user,$password);
   try { $ToolkitServiceObj = ToolkitService::getInstance($conn); }
   catch (Exception $e) { die($e->getMessage()); }
   $ToolkitServiceObj->setToolkitServiceParams(array(
   'InternalKey'=>$internalKey,  // *** RIGHT HERE internalKey/IPC
                                 // *** run state full ...
                                 //     use SBMJOB command run in new job
                                 //     PHP can call again, again, again
                                 //     with /tmp/packers and get ...
                                 //     same job every time
                                 //     same library list (*LIBL)
                                 //     same PGMs with open files, etc.
                                 //     ... exactly like 5250 sign-on screen
   'plug'=>"iPLUG32K"));         // max size data i/o (iPLUG4K,32K,65K.512K,1M,5M,10M,15M)
   // state full - MUST do this ONCE ONLY after start/sbmjob of XMLSERVICE job
   //              then forget about it (unless you choose to change libl) ...
   $ToolkitServiceObj->CLCommand("CHGLIBL LIBL(FREDFLIN WILMAFLIN) CURLIB(FREDFLIN)");
   /* Do not use the disconnect() function for "state full" connection */
   /* NEVER EVER USE THIS ... $ToolkitServiceObj->disconnect();        */
   /* Why? *immed kill of job, not nice or sync, just kill             */
   /* Use idle timeout for "state full" / "private" connections        */

XMLSERVICE adopt authority issues

When using ctl+ipc “state full” jobs is a generally bad idea to “adopt authority” as originating profile sally will lose all access … and … in fact ipc may become unreachable causing a orphan XMLSERVICE (client is still sally, ipc is still sally’s, but adopt xmlservice server becomes fred).

Two choices:

3) State full — hybrid “private/persistent” connection

These connections are hybrid “private/persistent” connection shared by many requesters, but keep open PGM, files, etc.

Worried about too many IPC’s/XMLSERVICE jobs??

The following gives you a hybrid “private/persistent” connection …

Try this simple technique for pooled IPC’s/XMLSERVICE jobs $internalKey = '/tmp/packers'.rand(1,$maxpool)

3) State full -- hybrid "private/persistent" connection
   $maxpool = 3;
   // -- PHP raw ---
   $ctl     = "*sbmjob";
   $ipc     = "/tmp/sally".rand(1,$maxpool);
   // -- or PHP toolkit --
   $internalKey = '/tmp/sally'.rand(1,$maxpool)

                    (1)           (2)           (3)                       (4)
                    Apache        FastCGI       DB2 (server mode)         XMLSERVICE
                    -------  ---------------    ---------------------     ----------
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--.
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|
                      :                                                 |
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally1) <--alive until stopped (or idle timemout)
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally2) <--alive until stopped (or idle timemout)
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally3) <--alive until stopped (or idle timemout)
                      :                                                 |
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--.

   3 XMSLERVICE jobs handle work for all sally clients using the site 

Example new Toolkit (hybrid "private/persistent" connection):

   $maxpool = 40; // 40 jobs good enough to handle my machine needs

   if ($i5persistentconnect) $conn = db2_pconnect($database,$user,$password);
   else $conn = db2_connect($database,$user,$password);

   try { $ToolkitServiceObj = ToolkitService::getInstance($conn); }
   catch (Exception $e) { die($e->getMessage()); }

   $internalKey = '/tmp/packers'.rand(1,$maxpool);
   $ToolkitServiceObj->setToolkitServiceParams(array(
   'InternalKey'=>$internalKey,  // *** RIGHT HERE internalKey/IPC $maxpool jobs for service
   'plug'=>"iPLUG32K"));         // max size data i/o (iPLUG4K,32K,65K.512K,1M,5M,10M,15M)

   /* Do not use the disconnect() function for "state full" connection */
   /* NEVER EVER USE THIS ... $ToolkitServiceObj->disconnect();        */
   /* Why? *immed kill of job, not nice or sync, just kill             */
   /* Use idle timeout for "state full" / "private" connections        */

4) State full — reservation hybrid “private/persistent” connection

These connections are hybrid “private/persistent” connection exclusively held for a period of time by each requesters, but returned back to pool for re-use.

If your client needs to start/use/stop a reservation hybrid “private/persistent” connection, use the appropriate keyword in your XML sent to XMLSERVICE to gain exclusive rights to the hybrid “private/persistent” connection.

4) hybrid "private/persistent" connection with reservation
   $maxpool = 3;
   // -- PHP raw ---
   $ctl     = "*sbmjob";
   $ipc     = "/tmp/sally".rand(1,$maxpool);
   // -- or PHP toolkit (not available yet -- Alan) --

                    (1)           (2)           (3)                       (4)
                    Apache        FastCGI       DB2 (server mode)         XMLSERVICE
                    -------  ---------------    ---------------------     ----------
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--.
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|
                      :                                                 |
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally1)       <--alive until stopped (or idle timemout)
                                                                           <start>unique-user-key</start> <--exclusive reservation until stopped
                                                                           <use>unique-user-key</use>
                                                                           <stop>unique-user-key</stop>
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally2) <--alive until stopped (or idle timemout)
                                                                           <start>unique-user-key</start> <--exclusive reservation until stopped
                                                                           <use>unique-user-key</use>
                                                                           <stop>unique-user-key</stop>
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|->XMLSERVICE (/tmp/sally3) <--alive until stopped (or idle timemout)
                                                                           <start>unique-user-key</start> <--exclusive reservation until stopped
                                                                           <use>unique-user-key</use>
                                                                           <stop>unique-user-key</stop>
                      :                                                 |
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--|
                  -->thread--socket->php-cgi--->QSQSRVR(profile sally)--.

   3 XMSLERVICE jobs handle work for all sally clients using the site
   However, reservation locks exclusive use until reservation is stopped.

Example new Toolkit (hybrid "private/persistent" connection with reservation):
--- unfortunately reservation is not available in PHP wrapper yet (Alan) ---
--- raw xml pseudo code version of what happens follows start/use/stop   ---
    -- no time out --
     $ctl .= " *idle(0)"
    -- request 1 --
     <?xml version="1.0"?>
     <script>
     <start>unique-user-key</start>
     </script>
    -- request 2 (two minutes later) --
     <?xml version="1.0"?>
     <script>
     <use>unique-user-key</use>
     <cmd exec='rexx'>RTVJOBA USRLIBL(?)</cmd>
     </script>
    -- request 3 (1/2 hour later) --
     <?xml version="1.0"?>
     <script>
     <use>unique-user-key</use>
     <pgm name='ZZCALL'> 
      <parm>
       <data type='1A'>a</data>
      </parm> 
      <return>
        <data type='10i0'>0</data>
      </return> 
     </pgm> 
     </script>
    -- request n (2 hours later) --
     <?xml version="1.0"?>
     <script>
     <stop>unique-user-key</stop>
     </script>

Author(s)

Tony “Ranger” Cairns - IBM i PHP / PASE

Retrieved from http://youngiprofessionals.com/wiki/index.php/XMLService/XMLSERVICEConnect
Page last modified on June 27, 2016, at 09:41 PM EST