title: Long Polling with Ajax and PHP - Apache freezes
body: <p>We try to implement long-polling based notification service in our company's ERP. Similar to Facebook notifications. </p>
  
  <p>Technologies used: </p>
  
  <ul>
  <li>PHP with <code>timeout</code> set to 60 seconds and 1 second <code>sleep</code> in each iteration of loop. </li>
  <li>jQuery for AJAX handling.</li>
  <li>Apache as web server.</li>
  </ul>
  
  <p>After nearly month of coding, we went to production. Few minutes after deployment we had to rollback everything. It turned out that our server (8 cores) couldn't handle long requests from 20 employees, using ~5 browser tabs each.
  For example: User opened 3 tabs with our ERP, with one long-polling AJAX on each tab. Opening 4th tab is impossible - it hangs until one of previous 3 is killed (and therefore AJAX is stopped).</p>
  
  <p>'Apache limitations', we thought. So we went googling. I found some info about Apache's MPM modules and configs, so I gave it a try. Our server use <code>prefork</code> MPM, as <code>apachectl -l</code> shown us. So I changed few lines in config to look something like this:</p>
  
  <pre><code>&lt;IfModule mpm_prefork_module&gt;
      StartServers          1
      MinSpareServers       16
      MaxSpareServers      32
      ServerLimit          50%
      MaxClients          150
      MaxClients           50%
      MaxRequestsPerChild   0
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Funny thing is, it works on my local machine with similar config. On server, it looks like Apache ignores config, because with <code>MinSpareServers</code> set to 16, it lauches 8 after restart. Whe have no idea what to do. </p>