Calling php-cli from a CL program

General discussion on Zend Server for IBM System i

Calling php-cli from a CL program

Postby deathcomp on Thu Jan 22, 2015 8:39 pm

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.
deathcomp
 
Posts: 34
Joined: Mon Feb 13, 2012 5:17 pm

Re: Calling php-cli from a CL program

Postby scottgcampbell on Thu Jan 22, 2015 10:39 pm

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
scottgcampbell
 
Posts: 187
Joined: Wed Apr 22, 2009 2:29 pm
Location: Edmonton, AB, Canada

Re: Calling php-cli from a CL program

Postby deathcomp on Fri Jan 23, 2015 2:44 pm

I'm probably just missing it, but which part there is the parm that gets passed along to the php script?
deathcomp
 
Posts: 34
Joined: Mon Feb 13, 2012 5:17 pm

Re: Calling php-cli from a CL program

Postby scottgcampbell on Fri Jan 23, 2015 3:06 pm

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
scottgcampbell
 
Posts: 187
Joined: Wed Apr 22, 2009 2:29 pm
Location: Edmonton, AB, Canada

Re: Calling php-cli from a CL program

Postby rdxwkpr on Thu Apr 09, 2015 6:32 pm

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.
rdxwkpr
 
Posts: 4
Joined: Mon Jan 10, 2011 6:51 pm

Re: Calling php-cli from a CL program

Postby aseiden on Tue Apr 14, 2015 12:48 am

Interesting idea. This way you don't have to null-terminate many separate parameters.
aseiden
 
Posts: 873
Joined: Thu Apr 09, 2009 5:45 pm

Re: Calling php-cli from a CL program

Postby kim4940 on Fri Apr 13, 2018 3:26 pm

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.....?
kim4940
 
Posts: 11
Joined: Wed Jul 22, 2015 8:23 pm


Return to Zend Server for IBM i

Who is online

Users browsing this forum: No registered users and 4 guests