There is a solution:
Use Gnu Screen
Send commands to screen
running in detached mode. Here is a quick-and-dirty example just to get you started:
<?php
// Start screen in detached mode, running htop
`screen -d -m -S htop_session htop`;
// let screen and htop start
sleep(1);
// Tell screen to save a screenshot in file 'hardcopy.0'
`screen -p 0 -S htop_session -X hardcopy`;
// Tell screen to quit
`screen -p 0 -S htop_session -X quit`;
?>
<pre>
<?php print file_get_contents('hardcopy.0'); ?>
</pre>
Things to try
- Experiment how to set a larger screen window size