InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $one = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $one = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $two = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $two = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $three = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $three = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $four = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $four = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $five = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $five = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $six = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $six = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $seven = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $seven = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $eight = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $eight = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $nine = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $nine = $cpu->LoadPercentage; $i++; } } } if(class_exists("COM")) { $wmi = new COM("WinMgmts:\\\\."); $cpus = $wmi->InstancesOf("Win32_Processor"); $i = 1; // Use the while loop on PHP 4 and foreach on PHP 5 if($phpver=="4"){ while ($cpu = $cpus->Next()) { $clockSpeed = $cpu->CurrentClockSpeed; $ten = $cpu->LoadPercentage; $i++; } } else{ foreach ($cpus as $cpu) { $clockSpeed = $cpu->CurrentClockSpeed; $ten = $cpu->LoadPercentage; $i++; } } } // Add values to the graph $graphValues=array($one,$two,$three,$four,$five,$six,$seven,$eight,$nine,$ten); // Define .PNG image header("Content-type: image/png"); $imgWidth=225; $imgHeight=100; // Create image and define colors $image=imagecreate($imgWidth, $imgHeight); $colorWhite=imagecolorallocate($image, 0, 0, 0); $colorGrey=imagecolorallocate($image, 0, 64, 0); $colorBlue=imagecolorallocate($image, 0, 255, 0); // Create border around image imageline($image, 0, 0, 0, 250, $colorGrey); imageline($image, 0, 0, 250, 0, $colorGrey); imageline($image, 249, 0, 249, 249, $colorGrey); imageline($image, 0, 249, 249, 249, $colorGrey); // Create grid for ($i=1; $i<11; $i++){ imageline($image, $i*25, 0, $i*25, 250, $colorGrey); imageline($image, 0, $i*25, 250, $i*25, $colorGrey); } // Create line graph for ($i=0; $i<10; $i++){ imageline($image, $i*25, ($imgHeight-$graphValues[$i]), ($i+1)*25, ($imgHeight-$graphValues[$i+1]), $colorBlue); } // Create some colors $white = imagecolorallocate($image, 255, 255, 255); $green = imagecolorallocate($image, 0, 160, 0); $black = imagecolorallocate($image, 0, 0, 0); // The text to draw $text = "Testing..."; // Replace path by your own font path $font = "tahoma.ttf"; $averagecpu=($one+$two+$three+$four+$five+$six+$seven+$eight+$nine+$ten) / 10; if(!($averagecpu=="0")){ $totalcpu="Average CPU Usage: " . $averagecpu . "%"; } else{ $totalcpu="WMI failed. Check config."; } // Add some shadow to the text imagettftext($image, 9, 0, 40, 55, $green, $font, $totalcpu); // Output graph and clear image from memory imagepng($image); imagedestroy($image); ?>