title: Monitoring apache's load with php
body: <p><strong>UPDATE:</strong> thanks to all the answer given, but they are all about the system load, and not the apache.</p>
  
  <p>My goal is to understand, inside my php scripts (the templating ones), when apache have an high load and is prefearrable to fork some traffic on lighttpd, that is here just to the long-polling and to light the apache's load.</p>
  
  <p>Hi guys, after <a href="https://stackoverflow.com/questions/1779317/best-way-to-handle-concurrency-issues" title="this question">this question</a> i've started to use lighttpd for a long-polling service on my server, in order to not to nuke apache and the database forn this kind of requests.</p>
  
  <p>Then, i started to use lighttpd also to static content (images, css, js, and so on).</p>
  
  <p>So, actually, i have example.com served by apache, and polling.example.com served by lighttpd, both using memcache to reduce the database hits.</p>
  
  <p>In apache, i've set the proxy module to proxy out all the requests to example.com/polling/* at polling.example.com/*</p>
  
  <p>Now, im wondering if there is a way to retrieve the apache server load in php, in order to redirect even other ajax requests on lighttpd if apache have an high load.</p>
  
  <p>I mean, something like:</p>
  
  <pre><code>&lt;?php
  $apache_server_load = /*hot to retrieve this value?*/;
  if($apache_server_load &gt;= $my_defined_max_load){
      $ajax_domain = '/polling';
  }else{
      $ajax_domain = '';
  }
  ?&gt;
  &lt;script&gt;
      [...]
      $.ajax({
          url: '&lt;?php echo $ajax_domain; ?&gt;/mypage.php',
          [...]
      });
      [...]
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>edit</strong> im running on Debian</p>
  
  <p>p.s: i'll also like to hear if this solution can be a nice approach, but would be another question.. feel free to comment if you like.</p>