title: How can I get the real CPU time used in PHP?
body: <p>How can I calculate the CPU time actually used by my php script?</p>
  
  <p>Note this is NOT what I'm looking for:</p>
  
  <pre><code>&lt;?php
  $begin_time=microtime(true);
  //..
  //end of the script:
  $total_time=microtime(true)-$begin_time;
  </code></pre>
  
  <p>because that would give me the time elapsed. That may include a lot of time used by unrelated processes running at the same time, as well as time spent waiting for i/o.</p>
  
  <p>I've seen there is getrusage(), but a user comment in the documentation page says:</p>
  
  <blockquote>
    <p>getrusage() reports kernel counters that are updated only once application loses context and a switch to kernel space happens. For example on modern Linux server kernels that would mean that getrusage() calls would return information rounded at 10ms, desktop kernels - at 1ms.</p>
    
    <p>getrusage() isn't usable for micro-measurements at all - and getmicrotime(true) might be much more valuable resource.</p>
  </blockquote>
  
  <p>so that doesn't seem to be an option,  is it?</p>
  
  <p>What alternatives do I have?</p>