Firstly i would like to say that i am a novice php enthusiast.
I am currently trying to write a script that gathers the process resources of my local system in order to produce a bar graph of the 6 most memory-hungry processes on my system.
I have managed to make my shell command execute inside the php script, however i do not know how to incorporate the output of my shell command into my values variabe, so that the graph can be generated.
Would you be able to suggest how this could be done?
Here is the script as it is so far, i am missing something that i just cannot resolve.
//Execute command via shell and return the complete output as a string
$output = shell_exec('ps ax -o rss,command | sort -nr | head -n 6');
// This array of values is just here for the example.
$values = array("23","32","35","57","12",
// Get the total number of columns we are going to plot
$columns = count($values);
// Get the height and width of the final image
$width = 300;
$height = 200;
// Set the amount of space between each column
$padding = 5;
// Get the width of 1 column
$column_width = $width / $columns ;
// Generate the image variables
$im = imagecreate($width,$height);
$gray = imagecolorallocate ($im,0xcc,0xcc,0xcc);
$gray_lite = imagecolorallocate ($im,0xee,0xee,0xee);
$gray_dark = imagecolorallocate ($im,0x7f,0x7f,0x7f);
$white = imagecolorallocate ($im,0xff,0xff,0xff);
// Fill in the background of the image
$maxv = 0;
// Calculate the maximum value we are going to plot
for($i=0;$i<$columns;$i++)$maxv = max($values[$i],$maxv);
// Now plot each column
$column_height = ($height / 100) * (( $values[$i] / $maxv) *100);
$x1 = $i*$column_width;
$y1 = $height-$column_height;
$x2 = (($i+1)*$column_width)-$padding;
$y2 = $height;
// This part is just for 3D effect
// Send the PNG header information. Replace for JPEG or GIF or whatever
header ("Content-type: image/png");