title: Apache Prefork/Worker MPM
body: <p>I'm just beginning to understand how an apache server works, andthe other day I ran into a problem when programming a very simple webpage while displaying a hit count for the page:</p>
  
  <pre><code>/* The simplest HelloWorld module */
  #include &lt;httpd.h&gt;
  #include &lt;http_protocol.h&gt;
  #include &lt;http_config.h&gt;
  
  static int noOfViews = 0;
  
  static int helloworld_handler(request_rec *r)
  {
  
      if (!r-&gt;handler || strcmp(r-&gt;handler, "helloworld")) {
          return DECLINED;
      }
  
      if (r-&gt;method_number != M_GET) {
          return HTTP_METHOD_NOT_ALLOWED;
      }
      noOfViews++;
  
      ap_set_content_type(r, "text/html;charset=ascii");
      ap_rputs("&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"&gt;\n",
               r);
      ap_rputs("&lt;html&gt;&lt;head&gt;&lt;title&gt;Apache HelloWorld "
               "Module&lt;/title&gt;&lt;/head&gt;", r);
      ap_rputs("&lt;body&gt;&lt;h1&gt;Hello World!&lt;/h1&gt;", r);
      ap_rputs("&lt;p&gt;This is the Apache HelloWorld module!&lt;/p&gt;", r);
      ap_rprintf(r, "&lt;p&gt;Views: %d&lt;/p&gt;", noOfViews);
      ap_rputs("&lt;/body&gt;&lt;/html&gt;", r);
      return OK;
  }
  
  static void helloworld_hooks(apr_pool_t *pool)
  {
      ap_hook_handler(helloworld_handler, NULL, NULL, APR_HOOK_MIDDLE);
  }
  
  module AP_MODULE_DECLARE_DATA helloworld_module = {
      STANDARD20_MODULE_STUFF,
      NULL,
      NULL,
      NULL,
      NULL,
      NULL,
              helloworld_hooks
  };
  </code></pre>
  
  <p>What basically happened is when I would refresh the page, the hit counter would go up, but sometimes it would randomly drop in number. Someone told me that it was because of the way the Apache Prefork MPM worked. After reading this: </p>
  
  <p><a href="http://httpd.apache.org/docs/2.0/mod/prefork.html" rel="nofollow">http://httpd.apache.org/docs/2.0/mod/prefork.html</a></p>
  
  <p>I understand the problem more, but I'm still not 100% sure whats going on. So the prefork MPM creates a bunch of child processes, some of them idle, and waits for clients to connect, so when I'm refreshing the page, I'm actually connecting to a bunch of different child processes the server is running. However, this module has a limited number of child processes it can keep up at the same time, so sometimes when it kills a process my counter goes down. I'm not entirely sure if this explanation is correct or why exactly the counter drops.</p>
  
  <p>All advice is appreciated. </p>