简体   繁体   中英

PHP script only return values if executed via command line

I have a php script that execute an external script to perform a task on a linux host, the script utilizes exec php function to run external command as follows:

<?php 

$user = "admin";

exec('cloudmonkey " list virtualmachines account=$user"', $outputArray);
echo implode("\n", $outputArray);

 ?>

Result when running the script via command line

# php cs-functions.php

{
  "count": 1,
  "virtualmachine": [
    {
      "account": "admin",
      "affinitygroup": [],
      "cpunumber": 2,
      "cpuspeed": 1000,
      "created": "2015-04-02T12:11:41-0400",
      "details": {
        "hypervisortoolsversion": "xenserver56"
      } ...etc 

But when I access the page using a browser, I get a blank screen.

What is the issue here?

Your help is highly appreciated.

Thank you

Try:

exec('cloudmonkey " list virtualmachines account=$user"', $outputArray);
$outputArray = json_decode($outputArray);
foreach ($outputArray as $key => $value){
    echo "$key: $value\n";
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM