IBM Support

Persistent C CGI programming example

News


Abstract

Persistent C CGI programming example

Content

You are in: IBM i Technology Updates  > Web Integration on i IBM HTTP Server for i > Introduction > CGI programming example > Persistent C CGI programming example

This sample code is provided by IBM for illustrative purposes only. It has not been fully tested. It is provided as-is without any warranties of any kind, including but not limited to the implied warranties of merchantability and fitness for a particular purpose.

This program demonstrates how CGI applications maintain state by keeping a CGI server job alive for multiple requests from a browser to the CGI application. This is accomplished through a persistent connections CGI application. The application tells the server it is a persistent CGI using the Accept-HTSession CGI header as the first header it returns. In this program a global static variable 'count' is incremented each time the program is called with a specific HTSesssion request.

To install the example program, do the following:

  1. Download this program source code file: 
  2. Use the following CL commands to create a directory structure: 
    1. mkdir dir('/qsys.lib/pcdemo.lib')
    2. mkdir dir('/qsys.lib/pcdemo.lib/qcsrc.file')
      Be aware the mkdir command uses  hierarchical file authorities, unless you specify otherwise, for the *PUBLIC users.  You may want to specifically add read and execute authorities for server user profiles QTMHHTTP and QTMHHTP1 to these new directories.
  3. Use FTP to connect to your server.
  4. Use the following FTP commands to copy the file to your server: 
    1. asc (optional)
    2. put persistc.txt /qsys.lib/pcdemo.lib/qcsrc.file/persistc.mbr
  5. Use the following CL commands to create the program (PGM) object called PERSISTC: 
    1. CRTCMOD MODULE(pcdemo/persistc) SRCFILE(pcdemo/qcsrc) SRCMBR(persistc) OUTPUT(*print)
    2. CRTPGM PGM(PCDEMO/PERSISTC) MODULE(PCDEMO/PERSISTC) ACTGRP(PCDEMO)
    The activation group parameter ACTGRP(PCDEMO) creates a named activation group called PCDEMO when the CRTPGM CL command runs. For persistent CGI programs to work, you must have a named activation group.  The activation group preserves certain job storage areas required for the program's data to persist.
  6. Use your browser to access the HTTP Server Configuration and Administration forms to create an Apache server named, for example, PCCONFIG.
    • Add the ScriptAlias directive below, using the URL Mapping form.
    • Add the directory for the QSYS (CDEMO.LIB) library, using the Context Managementform.  
    • Optionally, you may also add various directives for persistent CGI applications and timers using the Dynamic Content and CGI form.  
    • Under Tools, select Display Configuration File to make sure you have the following persistent CGI related directives (optional Persistent CGI directives are included):

      ScriptAlias /cgi-bin/ /QSYS.LIB/PCDEMO.LIB/
      PersistentCGITimeout 240 (seconds)
      MaxPersistentCGITimeout 600 (seconds)
      MaxPersistentCGI 10
      <Directory /QSYS.LIB/PCDEMO.LIB/>
          AllowOverride None
          SetHandler cgi-script
          Options +ExecCGI
          order allow,deny
          allow from all
      </Directory>
  7. Start the PCCONFIG server from the GUI.
  8. From your browser type: http://yourservername:port/cgi-bin/persistc.pgm?bin=1 .
The input for this program comes from the environment variable QUERY_STRING and uses request method GET.  Standard C APIs are used in the example.  HTTP server CGI application APIs like QtmhGetEnv would also work.

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Component":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
30 January 2020

UID

ibm11172224