Open-source Languages & Tools for z/OS

 View Only
  • 1.  PHP: Multi-line command results put into string variable

    Posted 03-22-2016 10:59

    Hi,

    I’ve been working with the z/OS Open Source version of PHP and found a behavior that is different then the previous version we’ve used. We commonly use PHP scripts to parse through the results of system commands at our shop for system checking and monitoring. One such example is a script that checks the available space in file systems. We’ll do something like this:

    $dfcmd = “df -kP"
    exec(”$dfcmd",$dfout,$dfrc);

    foreach ($dfout as $df) {
    #Check each filesystem
    }

    In the previous version of PHP the results from the command would result in $dfout being populated as an array with each output line as a separate array element. This allowed the following foreach loop to parse through the results. In the new version, $dfout is instead populated with a long string with the EOL characters included. Is this the desired behavior?

    Thanks!



  • 2.  RE: PHP: Multi-line command results put into string variable

    Posted 03-22-2016 16:21

    Right offhand it looks like a bug. We will look into it and get back to you.



  • 3.  RE: PHP: Multi-line command results put into string variable

    Posted 03-23-2016 15:21

    It seems to be working OK for me, using this script:

    <?php $dfcmd = "df -kP"; exec("$dfcmd",$dfout,$dfrc); var_dump($dfout); foreach ($dfout as $df) { echo $df."\n"; } ?>
    Can you please run that script and confirm the behavior you are seeing?

    If it still isn’t working as expected, can you please provide the build of PHP that you are running? The instructions for getting that information can be found here, and if you are running the latest build the output should be:

    Tool: php Version: 5.4.4 Build Number: 0003

    – Jerry



  • 4.  RE: PHP: Multi-line command results put into string variable

    Posted 03-24-2016 08:52

    I did still have the same issue running that script, but I couldn’t find the VERSION.ZOS that you asked for. I may be working with a unique build since it was sent to me by your support staff while working on a separate issue, so I’m going to download the newest version from the website and see if that makes a difference. I’ll let you know the results.



  • 5.  RE: PHP: Multi-line command results put into string variable

    Posted 03-24-2016 09:33

    The freshly downloaded version did fix the issue. Thank you for your help!



  • 6.  RE: PHP: Multi-line command results put into string variable

    Posted 03-24-2016 11:35

    Excellent! Thanks for letting me know.