Is it possible to display the commands like 'top' on webpage using php?
<?php
echo shell_exec('top');
?>
Is it possible to display the commands like 'top' on webpage using php?
<?php
echo shell_exec('top');
?>
maybe this:
<?php
$output = null;
exec('top -n 1', $output);
var_dump($output);
?>
If I understand your question correctly, you're trying to get an interactive program showing on the client with live updates. This is not possible as you've demonstrated.
It seems you may not understand what's going on with PHP. PHP runs on the server before the page is downloaded by the client. The client then gets a 'snapshot' of the page as the server rendered it. Once the page is loaded on the user's machine, the server cannot touch the page.
To get interactive content, you have a few options (from least desirable and easiest to most desirable and most involved):
Another problem is that interactive commands like top
use a bunch of terminal-specific (refresh the terminal, rewrite bits of text, etc.) that will mess up the output in the browser. You'll need to do something like @David said and get a snapshot of the output and get that to the user periodically (choose one from above).
There are lots of libraries and tutorials for PHP available for whichever route you choose.