Page 1 of 1

Calling php-cli from a CL program

Posted: Thu Jan 22, 2015 8:39 pm
by deathcomp
We have several instances where we use the CALL PGM(QP2SHELL) command in CL to call a php script. For example we might do:

CALL PGM(QP2SHELL) PARM('usr/local/zendsvr/bin/php-cli' '/scripts/myScript.php')

This would then run that php script located in /scripts.

Our problem is how to pass a parm to the php script. If I was doing this manually from qsh, i would just navigate to the /usr/local/zendsvr/bin directory and run "php-cli /scripts/myScript.php MyParm"

How can we do that calling it from CL? Would it just be:
CALL PGM(QP2SHELL) PARM('usr/local/zendsvr/bin/php-cli' '/scripts/myScript.php' 'MyParm')

Or is there a different syntax.

Re: Calling php-cli from a CL program

Posted: Thu Jan 22, 2015 10:39 pm
by scottgcampbell
Here is what I have to call from CL (using qsh instead of qp2shell):

Code: Select all

CHGVAR     VAR(&CMD) VALUE('. +                            
             /usr/local/zendsvr6/bin/php-cli +             
             /www/zendsvr/htdocs/stand_alone/brmslogs.ph+  
             p ' *CAT &JOBNAM *TCAT '.' *TCAT &JOBUSR +    
             *TCAT '.' *TCAT &JOBNBR)                      

SBMJOB     CMD(QSH CMD(&CMD)) JOB(BRMSLOGS) +              
             JOBQ(WEBJOBS) USER(SUPPORT) LOG(4 0)
So just about what you have but I don't have quotes around the parms for the script.

Scott

Re: Calling php-cli from a CL program

Posted: Fri Jan 23, 2015 2:44 pm
by deathcomp
I'm probably just missing it, but which part there is the parm that gets passed along to the php script?

Re: Calling php-cli from a CL program

Posted: Fri Jan 23, 2015 3:06 pm
by scottgcampbell
Sorry, that would be the job info with periods in between, everything after the script name will be passed to the script in $argv

Code: Select all

*CAT &JOBNAM *TCAT '.' *TCAT &JOBUSR +    
             *TCAT '.' *TCAT &JOBNBR
Scott

Re: Calling php-cli from a CL program

Posted: Thu Apr 09, 2015 6:32 pm
by rdxwkpr
I know this is an old post but thought that someone might be helped by it. This is an example of what we submit using php-cli with parameters:

CALL PGM(QP2SHELL) PARM('/usr/local/zendsvr6/bin/php-cli' '/your_path/your_script.php C2::HD_C2_DB::2::4::1::s')

Your script then pulls the values out: $Arg = explode ( "::", $argv [1] );

Hope that helps.

Re: Calling php-cli from a CL program

Posted: Tue Apr 14, 2015 12:48 am
by aseiden
Interesting idea. This way you don't have to null-terminate many separate parameters.

Re: Calling php-cli from a CL program

Posted: Fri Apr 13, 2018 3:26 pm
by kim4940
I'm able to pass a parameter into a php script via CL, using QP2SHELL, but what about php then returning a parameter back to the calling CL? Is that possible? I've tried everything I can think of.

Here is my call within my CL program -

CALL PGM(QP2SHELL) +
PARM('/usr/local/zendphp7/bin/php-cli' +
'/mypath/myphpscript.php' +
&PARAMTOPHP &PARAMFROMPHP)

Then in the PHP script I've set $argv[2] to a value to return back to the CL, but apparently it doesn't work that way.....?