KB Article 15963
2018/12/21

Close
X
Contact Tech Support

 Email Tech Support
 (250) 655-1766
 [7:30 - 5:00 PST]
Your Meeting ID will be Provided by a Rep.
Tech Support
Tech Support Home
Software Updates
Knowledge Base Search
Recent KB Articles
Product FAQs
Code Samples
Documentation
Tech Blog
System Requirements
Installation Instructions
Support Testimonials
Contact us to...
Create a Ticket
Request a Free Demo
Suggest a New Feature
Submit Feedback
Upload a Large File
Other Services
Software Training
Professional Services

Statefullness and calling multiple programs with the PHP Toolkit

Product: WebSmart PHP Type: How to

By default the PHP Toolkit is not stateless, ie it is statefull. This is handled in part by an IPC internal key which allows a stateful, private job to handle toolkit requests, allowing a php script to return to the same toolkit job over many requests. It can be specified with a statement like:

$tkConnection->setToolkitServiceParams(array('stateless'=>false, 'InternalKey'=>"/tmp/mykey");

Where the value for the internal key is an IFS directory that need not exist. By default the InternalKey value will be: "/tmp/Toolkit". Using these defaults is not Zend's recommended practice. If you are using statefull programming they recommend that you give the internal key a unique value.

By using these default settings, one can run into issues where all toolkit requests are using the same job and sharing information (see KB#15040). It can lead to issues where the key gets locked by a job that crashes or if the connection is not ended properly. It can also cause problems with multiple calls to the PHP Toolkit within the same request.

___

Stateless PHP Toolkit Connections

One of the recommended ways of running the Toolkit is to run it statelessly. Program calls under this setting will be run within the database transport jobs rather than creating additional jobs for each session. This alleviates a lot of the problems above and can be done with a statement like:

/* Make the toolkit connection stateless (note: default is not) */
$tkConnection->setToolkitServiceParams(array('stateless'=>true));

(If you are using WebSmart's Snippet: Smart Program Call - Toolkit - WS this can go right before Step 2.) If you are trying to make multiple calls to a program this is the recommended way to make it work.

Ex) (Changes from the Smart Snippet are highlighted)

/* Clean fresh start with the tk connection. (This is to wipe out any previously set paramters as well.)*/
$tkConnection='';

/************* Step 1: Setup IBM i connection **************/
/* Either fill in the fields with your host, user, and */
/* password, or leave blank for a default local connection */
/*                                                                         */
/* getInstance(host, user, password, extension); */
/*                                                                  */
/* extension can be one of 'ibm_db2' or 'odbc' */
try
{
      $tkConnection = ToolkitService::getInstance('*LOCAL', '', '', 'ibm_db2');
}
catch (Exception $ex)
{
      echo $ex->getMessage() . "<br>\n";
      echo 'File: ' . $ex->getFile() . ':' . $ex->getLine() . "<br>\n";
      die();
}

/* Make the toolkit connection stateless (note: default is not) */
$tkConnection->setToolkitServiceParams(array('stateless'=>true));

/************** Step 2: Setup parameter list *****************/
/* Specify char parameters with: */
/* $tkConnection->AddParameterChar(dir, length, desc, name, value) */
/*                                             */
/* Specify dec parameters with: */
/* $tkConnection->AddParameterPackDec(dir, length, dec, desc, name, value) */
/*                                            */
/* Specify int parameters with: */
/* $tkConnection->AddParameterInt32(dir, desc, name, value) */
/*                                               */
/* Specify float parameters with: */
/* $tkConnection->AddParameterFloat(dir, desc, name, value) */
/*                                                                 */
/* dir Can be one of 'input', 'output', or 'both' */
/* length The length of the field */
/* dec The amount of decimal places */
/* desc A text description of the field */
/* name The name of the variable in the PGM */
/* value The value to pass to the PGM */
/* See here for more information: http://files.zend.com/help/previous-version/Zend-Server-5.1-IBMi/define_program_parameters.htm */
$params[] = $tkConnection->AddParameterChar('in', 77, '', 'subj', $subj);
$params[] = $tkConnection->AddParameterChar('in', 2000, '', 'body', $body);


/************** Step 3: Call the program ******************/
/* Results are returned in $result['io_param'] on success */
/* By default we extract them to the global scope */

$result = $tkConnection->PgmCall('spamtrav', 'xl_webapps', $params, NULL, NULL);
if ($result)
{
      extract($result['io_param']);

      // It is recommended to put any code relying on the
      // returned values from the PGM call in this block
      //echo 'subj: ' . $subj . '<br>';
      //echo 'body: ' . $body . '<br>';

}
else
{
      echo 'Error executing PGM.';
}

/************** Step 4: Close connection *****************/

//Disconnect not required when it is stateless
//$tkConnection->disconnect();

___

For more information you can also check out:

http://files.zend.com/help/Zend-Server-6-IBMi/content/setting_the_xml_service_options.htm

Rate This Article

Did this example help you to achieve your goal?
 Yes  No  Don't Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

Email Address:
Comments:
Please enable JavaScript in order to rate this page.