ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

PHP program call to RPG running too long times out.

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PHP program call to RPG running too long times out.

    I have a PHP program that calls a RPGLE program that runs a report. The browser times out sometimes.
    I set the timeout settings in IE11 and FireFox 29 but still have the problem.

    What I would like to do is have a way to submit the job and monitor its progress from a php program
    until it completes.

    I used WebSmart PHP tool to create the PHP program that contains the function below:

    PHP Code:
    function prtctl()

        
    // Make all global variables available here
        
    foreach($GLOBALS as $arraykey=>$arrayvalue
        {
            if (
    $arraykey != "GLOBALS")
            {
                global $
    $arraykey;
            }
        }  
        
    // Get the key field values which identify the record
        
    session_start();
        
    $_SESSION['views'] = 1// store session data    
        
    $USERID $_SESSION['USERID'];
        
    $LIBNAME $_SESSION['LIBNAME'];
        
    $LOCNAM $_SESSION['LOCNAM'];
        
    $_SESSION['LOCNAM'] = $LOCNAM;
        
    $Starttime $_SESSION['Starttime'];;
        
    /* library and program name:                       */   
        
    $lib $LIBNAME;    
        
    $prgmsg="PRTCRRPT - Print Delinquent Accounts for Reporting";
        
    $PSDCODE "Printed Code:  ";
        
    $PSCODE " ";
        
    /********** Step 1: set up parameter list description ************/
        /* Create an array that specifies the name of      */
        /* the input, the IO being performed, the variable */
        /* type, and the variable name.                    */
        
    $description = array(
        array(
        
    "Name"=>"PSCODE",
        
    "IO"=>I5_INOUT,
        
    "Type"=>I5_TYPE_CHAR,
        
    "Length"=>"1"
        
    ) ,
        array(
        
    "Name"=>"NONOTP",
        
    "IO"=>I5_INOUT,
        
    "Type"=>I5_TYPE_CHAR,
        
    "Length"=>"7"
        
    ) ,
        array(
        
    "Name"=>"PGDATE",
        
    "IO"=>I5_INOUT,
        
    "Type"=>I5_TYPE_CHAR,
        
    "Length"=>"10"
        
    )
        );    
        
    $name $lib "/" "PRTCRRPT"
        
    /********** Step 2: prepare the program for calling **************/
        
    $pgm i5_program_prepare($name$description);
        
        
    // Check if any errors occurred.
        
    if (!$pgm)
        {    
            echo 
    "<br>";
            
    print_r(i5_errormsg());
            
    i5_program_close($pgm);
            die(
    "i5_program_prepare");
        }
        
    /********** Step 3: assign the parameter values to send **********/
        /* Create an array with the input names and the    */
        /* corresponding values.  You need to supply the   */
        /* actual parm values.                             */
        
    $in_parameters = array(
        
    "PSCODE"=>"$PSCODE,
        
    "NONOTP"=>"$NONOTP,
        
    "PGDATE"=>"$PGDATE"
        
    );
        
    /********** Step 4: the parameters that will be returned *********/
        /* Create an array with the output parameters      */
        /* returned by the program.                        */
        
    $out_parameters = array(
        
    "PSCODE"=>"PSCODE" ,
        
    "NONOTP"=>"NONOTP" ,
        
    "PGDATE"=>"$PGDATE"
        
    );
        
    /******   set tim limit for job  **********************/ 
        
    set_time_limit(0);
        
    error_reporting(E_ALL);
        
    ob_implicit_flush(TRUE);
        
    ob_end_flush();
        
    //    set_time_limit(180);
        /********** Step 5: Call the program. ***************************/
        
    $ret i5_program_call($pgm$in_parameters$out_parameters);    
        
    $anonotp number_format($NONOTP,0);
        
    // Check if any errors occurred.
        
    if (!$ret
        {
            
    $prgmsg "Call to PRTCRRPT was not successful";
            
    $color="red";
            
    $anonotp "";
            
    wrtseg(MainSeg);
            
    wrtseg(ClsSeg);
            
    wrtseg(FootSeg);
            
    i5_program_close($pgm);
            die(
    "i5_program_call");
        }
        global 
    $db2conn;
        
    $db2conn xl_db2_connect($options);
        if(!
    $db2conn)
        {
            
    error_log("Failure to connect... Reopening connection");
            
    // close and reopen the connection to try again
            
    db2_close($db2conn);
            
    $db2conn xl_db2_connect($options);
            if(!
    $db2conn)
            {
                
    $db2conn xl_db2_connect($options);
                if (!
    $db2conn)
                {
                    die(
    'Failed to connect to database!');
                }
            }
        }
        
        
    $prgmsg "PRTCRRPT - Print Delinquent Accounts for Reporting - Completed";
        
        
    $color="teal"
        
    // Close the program handle (unload from memory).
        
    $Endtime time();
        
    $elapsetime $Endtime-$Starttime;
        
    $secs $elapsetime;
        
    $time_elapsed "Run Time:  ";    
        
    $elapsed time_elapsed($secs);
        
    $ret $elapsed;
        
    wrtseg(MainSeg);
        
    wrtseg(ClsSeg);
        
    wrtseg(FootSeg);
        
    i5_program_close($pgm);
        
    //Release the database resource
        
    db2_close($db2conn);
    }
    function 
    time_elapsed($secs)
    {
        
    $bit = array(
        
    ' year '        => $secs 31556926 12,
        
    ' week '        => $secs 604800 52,
        
    ' day '        => $secs 86400 7,
        
    ' hour '        => $secs 3600 24,
        
    ' minute '    => $secs 60 60,
        
    ' second '    => $secs 60
        
    );    
        
        foreach(
    $bit as $k => $v){
            if(
    $v 1)$ret[] = $v $k '(s)';
            if(
    $v == 1)$ret[] = $v $k;
        }
        
    array_splice($retcount($ret)-10);
        
    $ret[] = ' elapsed';
        
        return 
    join(' '$ret);    

    Does anyone have a idea how to do this?

    James R. Martin
    e-mail: jmartin@jmartinassociates.net


  • #2
    Re: PHP program call to RPG running too long times out.

    James

    Not sure what you mean by your Browser times out? Is it when you try to refresh the page? I am guessing but without any more knowledge it could be the maximum time scripts are allowed to run which is being exceeded?? This is a setting in the php.ini file which can be changed so longer scripts can be run. I know you can change various PHP settings on the fly but I am not sure if this is one of them?? If it is this then you should be able to research it and fix accordingly.

    Does that make sense?

    Chris...

    Comment


    • #3
      Re: PHP program call to RPG running too long times out.

      James

      Sorry I just noticed that you are using the set_time_limit(). So just need to know what the problem really is before I can make more suggestions.

      Chris...

      Comment


      • #4
        Re: PHP program call to RPG running too long times out.

        James

        Another place to check is the httpd.conf. It has a maximum run time for connections as well (TimeOut 30000)

        Chris...

        Comment


        • #5
          Re: PHP program call to RPG running too long times out.

          Originally posted by chris_hird View Post
          James

          Another place to check is the httpd.conf. It has a maximum run time for connections as well (TimeOut 30000)

          Chris...
          Chris

          I had already made the changes to php.ini and I made changes to httpd.conf. Still times out.

          I am changing it to call a CLLE program that will submit the RPGLE program and plan to add to the program
          a file that will be updated by the RPGLE program as it processes with a start and end time for the job and
          add to the php program script to check the file at intervals to determine when the RPGLE program finishes.

          James

          Comment


          • #6
            Re: PHP program call to RPG running too long times out.

            What is the connection with the browser? Is it being refreshed, and how?

            Comment


            • #7
              Re: PHP program call to RPG running too long times out.

              Originally posted by ralphdaugherty View Post
              What is the connection with the browser? Is it being refreshed, and how?
              Ralph:

              The connection to this browser is Zend Server on System i running Apache Http server.

              WebSmart PHP has:

              PHP Code:
              require('/esdi/websmart/v8.9/include/xl_functions001.php');
              require_once 
              'CW/cw.php';
              .
              .
              .
              if(!(
              $i5conn xl_i5_connect()))
                  die(
              "Unable to get an i5 connection");  
              global 
              $db2conn;
              $db2conn xl_db2_connect($options);
              // Retrieve the task (default to "default")
              if(!$db2conn)
              {
                  
              $db2conn xl_db2_connect($options);
                  if (!
              $db2conn)
                  {
                      
              error_log("Failure to connect... Reopening connection");
                      
              // close and reopen the connection to try again
                      
              db2_close($db2conn);
                      
              $db2conn xl_db2_connect($options);
                      if(!
              $db2conn)
                      {
                          
              $db2conn xl_db2_connect($options);
                          if (!
              $db2conn)
                          {
                              die(
              'Failed to connect to database!');
                          }
                      }
                  }



              xl_db2connect
              Description
              Creates a new connection to an IBM DB2 Universal Database.
              Function Prototype
              resource xl_db2_connect(array options)


              This function wraps db2_connect. The database, username and password are all specified

              in the included file xl_functions001.php.


              cw.php is the PHP Client: Toolkit API and Compatibility Wrapper (CW)
              http://174.79.32.155/wiki/index.php/XMLSERVICE/PHP


              On a side note, I am using WebSmartV8.9 (standalone) version. It cost a lot less and will still run
              php on iSeries. I have installed Zend Server CE on my iSeries 270 which runs In the IFS. I also
              installed Zend Server CE version 5.6.0 on my windows 7 Pro running PHP Version 5.4.0 and MySQL
              version 5.6 planning to install DB2 Express C version 10.1

              The application that is timing out does not refresh it waits on the RPGLE program to complete and RETURN.

              I plan to use Auto Refresh Div Content Using jQuery and AJAX in the php program script to check the file, I am adding as stated earlier, at intervals
              to determine when the RPGLE program finishes.

              James

              James R. Martin
              e-mail: jmartin@jmartinassociates.net

              Comment

              Working...
              X