<?php while(1){ exec('top -b -n 1 -d 3',$out); $Cpu = explode(' ', $out[2]); $Mem = explode(' ', $out[3]); $Swap = explode(' ', $out[4]); //var_dump($Cpu,$Mem,$Swap); $cpu = str_replace(array('%us,',' '),'',$Cpu[1]); $mem = str_replace(array('k used,',' '),'',$Mem[2]); $swap = str_replace(array('k cached',' '),'',$Swap[5]); echo date('md H').' '.$cpu.' '.intval($mem/1024).' '.intval($swap/1024).chr(10); sleep(10); }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)