get system cpu frequency in php

To get the system CPU frequency in PHP, you can use the following code:

main.php
$freq = shell_exec('cat /proc/cpuinfo | grep -i mhz | awk \'{print $4}\'');
echo "CPU frequency: $freq MHz";
109 chars
3 lines

This code executes a shell command using shell_exec(), which retrieves the CPU information from the /proc/cpuinfo file. The grep -i mhz command filters the lines containing the CPU frequency, and the awk '{print $4}' command selects the 4th column of these lines (which contains the frequency value). The frequency is then stored in the $freq variable and printed out using echo.

related categories

gistlibby LogSnag