call php with parms
Last Post 12 Mar 2008 06:38 PM by Scott Klement. 9 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
jogisarge
New Member
New Member
Posts:35

--
11 Mar 2008 03:43 PM
hello, how can i call a php script with parms. normally it works like this: [PHP] QSH CMD('/usr/local/zend/Core/bin/php -f + /path/to/myscript.php?parm1=p1&parm2=p2') [/PHP] but for me it throws an error
.. cant find the script /path/to/myscript.php?parm1=p1&parm2=p2
Can anybody tell how to call with parms ? bye jogi
WillyRose
Advanced Member
Advanced Member
Posts:360

--
11 Mar 2008 04:11 PM Accepted Answer
I haven't played with php on the iSeries yet, Jogi but certainly that's how php works normally. I'm assuming your variables are called &parm1 and &parm2 in your php script and you're assigning character values "p1" and "p2" to them, respectively? You've definitely specified the correct path?
jogisarge
New Member
New Member
Posts:35

--
11 Mar 2008 04:22 PM Accepted Answer
the scripts works fine without the parms [PHP] QSH CMD('/usr/local/zend/Core/bin/php -f + /path/to/myscript.php') [/PHP] this works. so the path must be ok
Ringer
Veteran Member
Veteran Member
Posts:1761
Avatar

--
11 Mar 2008 05:54 PM Accepted Answer
Did you check the Zend Core error log for any clues? Is usually here: /usr/local/Zend/Core/logs/php_error_log And does the php script check the $_POST array instead of the $_GET array for the parm values? Passing parms in the URL is a GET. I'm just wondering if the script itself is throwing that error (and and not Zend Core engine) because it is not finding what it expects to find (parms in $_POST). Chris
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16387
Avatar

--
12 Mar 2008 01:29 AM Accepted Answer
The way you've coded your "parameters" looks like you're confusing parameters with URL-encoded form data passed by a browser. That form data is NOT the same thing as a parameter, and it DOES require an HTTP server... To pass them as parameters, you'd have to code them as space-delimited values on the QShell command line -- but of course, your PHP script might have to be changed to look for parameters if it's really designed to get HTTP form data, passing it parameters won't help. You could try setting environment variables instead:

     ADDENVVAR ENVVAR(REQUEST_METHOD) +
               VALUE('GET') +
               REPLACE(*YES)

     ADDENVVAR ENVVAR(QUERY_STRING) +
               VALUE('parm1=p1&parm2=p2') +
               REPLACE(*YES)

     QSH CMD('/usr/local/zend/Core/bin/php -f +
              /path/to/myscript.php')
Honestly, I have no clue if that'll work or not -- but, normally an HTTP server (like Apache) would set these variables if were calling a CGI script, and the CGI script would check the variables to get it's data -- I suspect that PHP gets it's data the same way, and therefore this might work.
jogisarge
New Member
New Member
Posts:35

--
12 Mar 2008 06:41 AM Accepted Answer
Thanks Scott but that doesnt work für me. The php-script cant catch the parms. i thought, others should have the same, because using a php-script to make a request ober the www is a normal process today. my thoughts were: if i press in a green-screen app(article-management) the Fxx Button a cl is called in the Background. This cl calls the php-script and the article-number must be delivered to the php-script. The php-script takes the delivered number and makes a soap call over the www to get the stock of the article. p.s. it could happen, that 2 or more users call the php script at the same time Has anybody an idea Bye jogi
jogisarge
New Member
New Member
Posts:35

--
12 Mar 2008 06:50 AM Accepted Answer
Hello again, i have a workaround !!!!!! [PHP] QSH CMD('/usr/local/zend/Core/bin/php -f + /path/to/myscript.php p1 p2') [/PHP] in my php-Script i can access the superglobal array argv ! $argv[0] ist the scriptpath $argv[1] is p1 $argv[2] is p2 you only have to know wich parm is the right for you
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16387
Avatar

--
12 Mar 2008 02:04 PM Accepted Answer
Yes... that's how you pass parameters (normal parameters, not data from a form) to a PHP script...
Ringer
Veteran Member
Veteran Member
Posts:1761
Avatar

--
12 Mar 2008 02:15 PM Accepted Answer
Cool. Is there a way to return parm values back? Or do you have to do something like stuff values into a data area? Hmmm... I wonder if php putting values into the $_ENV array would make them available as environment variables to the CL program. If I get time, I will have to try that. That would make those thousands of php functions available to CL and RPG. Chris
Scott Klement
Editorial Staff Member
Editorial Staff Member
Posts:16387
Avatar

--
12 Mar 2008 06:38 PM Accepted Answer
typically, on Unix and Windows systems, parameters are input-only. You can pass parameters into a program, but not pass them out. (This restriction only applies to PROGRAMS, not function -- aka subprocedure -- calls.) Since PASE, QShell and PHP are all designed for a Unix-like environment, they do not allow two-way parameters. Instead, programs typically use stdin/stdout for passing info into and out of programs. PHP should have no trouble writing data to stdout (indeed, that's how it normally returns output to the browser.) Unfortunately, it's a PITA to read that output from CL (IMHO). Perhaps the easiest thing is to have PHP write it's stdout to a data queue (via the 'dataq' Qshell command) and then read that data queue from CL. Another idea is to write the STDOUT output to a file (via OVRDBF) and then read the file from the CL program -- but CL's limitations on reading files can become a problem in that case... which is why I've recently started using data queues.
You are not authorized to post a reply.

Acceptable Use Policy