title: Get cpu percent usage in php
body: <p>I want to show percent CPU usage in PHP. Is not important if get values by cron in shell > output to file > parse in PHP or directly get value in php. I try many solutions found on internet but nothing was useful. With load average I can't display 0-100% graphic bar and functions I found for percentage output give me bad values or only value for first core. It would be nice to get number of percentage usage for every core. Is there solution for this?</p>
  
  <p>EDIT:</p>
  
  <p>I make temporary solution, it works good but it is not best way.</p>
  
  <p>cron job every one minute run php script which exec command for grep cpu info from "top" and save it to file, on end script wait 3 seconds and loop 20-times (way to get update every 3 seconds)
  php script:</p>
  
  <pre><code>&lt;?php
  for($i=0; $i&lt;=20; $i++) {
      //cpu load
      exec("top -b -n 1 | grep 'Cpu(s):' &gt; /some/file.cpu");
      //ram usage
      exec("top -b -n 1 | grep 'Mem:' &gt; /some/file.ram");
      //wait 3sec
      sleep(3);
  }
  ?&gt;
  </code></pre>
  
  <p>and now from this files I can parse informations.</p>
  
  <p>New question is how to make daemon script to run this commands every 3 seconds. I think solution with php script and cron is only temporary solution and is not best way. daemon will be much better.</p>