Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6910655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:50:34+00:00 2026-05-27T08:50:34+00:00

I created a simple Apache server module following a sample hello world module I

  • 0

I created a simple Apache server module following a sample hello world module I found somewhere. Then I added a variable that would track the number of visits on my page. Here is my module code:

/* The simplest HelloWorld module */
#include <httpd.h>
#include <http_protocol.h>
#include <http_config.h>

static int noOfViews = 0;

static int helloworld_handler(request_rec *r)
{
    noOfViews++;

    if (!r->handler || strcmp(r->handler, "helloworld")) {
        return DECLINED;
    }

    if (r->method_number != M_GET) {
        return HTTP_METHOD_NOT_ALLOWED;
    }

    ap_set_content_type(r, "text/html;charset=ascii");
    ap_rputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n",
             r);
    ap_rputs("<html><head><title>Apache HelloWorld "
             "Module</title></head>", r);
    ap_rputs("<body><h1>Hello World!</h1>", r);
    ap_rputs("<p>This is the Apache HelloWorld module!</p>", r);
    ap_rprintf(r, "<p>Views: %d</p>", noOfViews);
    ap_rputs("</body></html>", 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
};

My module is currently experiencing 2 problems that I am unable to figure out.

  1. My views count seems to go up in multiples of 2 even though I only want it to increment 1 at a time.

  2. When I constantly refresh my page, sometimes my number randomly falls.

Does anyone know what the sources of my problems could be?

Thank you guys so much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:50:34+00:00Added an answer on May 27, 2026 at 8:50 am
    1. You’re incrementing your counter for requests that you don’t actually handle.

    2. Each worker process in Apache has its own copy of noOfViews. This applies whether you’re using the prefork or worker MPM; it’s just more a pronounced issue with prefork.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a server application that accepts connections over SSL. It's simple and
Hi My web server is Apache.I have created a sample application in my local
I'm using simple apache http linux mandriva server. I have created an ajax page
I created a simple dialog-based application, and in the default CDialog added three buttons
I have a site hosted on an Apache server. I have created some custom
I created my own apache module in C API with Python. #include httpd.h #include
I have created a simple mod_perl module, which writes a 0-terminated string to the
Could someone help me on this, I have created simple web services using axis2
How to manually create Friendly URLs? (PHP) So I have created simple php file
I created a simple .NET windows application in Visual Studio 2005 and on just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.