1
我創建了一個簡單的Apache服務器模塊,遵循我在某處找到的示例hello world模塊。然後我添加了一個變量來跟蹤我的頁面上的訪問次數。這裏是我的模塊代碼:簡單的Apache服務器模塊
/* 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
};
我的模塊目前遇到2個問題,我無法弄清楚。
我的觀點數似乎以2的倍數增加,即使我只希望它每次增加1。
當我不斷刷新我的頁面時,有時我的號碼會隨機下降。
有沒有人知道我的問題的根源是什麼?
謝謝你們這麼多!