Skip to content

Instantly share code, notes, and snippets.

@wwng2333
Last active January 5, 2017 13:06
Show Gist options
  • Save wwng2333/069a5efa267df95e1c4c34580ed912e6 to your computer and use it in GitHub Desktop.
Save wwng2333/069a5efa267df95e1c4c34580ed912e6 to your computer and use it in GitHub Desktop.
获取CPU温度
<?php
$cmd = 'sensors';
exec($cmd,$result);
$arr = array();
for($i=0;$i<count($result);$i++) {
$linenow = $result[$i];
while(strstr($linenow,' ')) {
$linenow = str_replace(' ','',$linenow); //去空格
}
if(strstr($linenow,'Core')) {
$temp = explode('(',$linenow);
$temp = explode(': ',$temp[0]);
$name = $temp[0];
$val = $temp[1];
$arr[$name] = $val;
} else {
continue;
}
echo json_encode($arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment