Search code examples
phplinuxhtop

using php to stream data of programs such as `htop`


using one of those codes

system("htop");
//or
exec('htop');

how to keep the data from htop being written into a file or something (time limit of the script is set to 0 don't worry)


Solution

  • htop is an interactive program that runs in a loop until exited, and doesn't seem to offer any flags to do a single iteration then exit which makes capturing the output problematic.

    Have you considered using top? You can limit it to 1 iteration with -n 1:

    $resp = system("top -n 1");
    print $resp;