c++ cgi counter: holding env vars in memory after execution

Posted on 2003-02-24
Medium Priority
Last Modified: 2013-12-25

I have a cgi logger with a hitcounter (for websites) written in c++ that reads an integer from a file,
updates the number with 1 and writes the new number back to the file.
This works fine, but now I would like to store information obtained from
cgi env vars, like REMOTE_ADDR, HTTP_USER_AGENT, etc together with a date stamp as well.

I have tried this with two seperate files (one for actual hitcount, one for env vars)
and that's working fine. The problem is that with a large amount of hits (50.000+ per hour)
the harddisk is constantly busy. So what I would like to do is somehow store those env
vars in an array (any other datatype will do as well of course), and have a cronjob write
the contents of the array once a minute to the harddisk and empty the array, so it can be filled with hits from the following minute again.

With this minute flushing the memory shouldn't get too filled, while the gain in speed is very high. Now my question is basically how to access one and the same array every time.
Since the counter is called in the actual html page (the counter is not a background-app, like a service in windows), the program closes everytime, deleting all the arrays, and other variables defined.

The only thing that comes to my mind is to manually specify the address of the memory for the array, but since there's no telling how big the one-minute buffer is going to be, this can easily cause memory problems.

There are three demands for this module:
1. it must be written in ansi c++ (must be able to run on linux, bsd)
2. it can not run as a background service
3. it must be fast

If there's anything unclear, please let me know.
Thank you
Question by:Aheib
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 8017296
points increased to 175.

Maybe I have more luck asking in the c++ section?

Accepted Solution

MatrixDud earned 700 total points
ID: 8041833
Have you tried a memory map

here's a bit of info...you'll probably have to doa bit more digging


Author Comment

ID: 8048653
Nope, never looked into that.
You're throwing me a bit in the deep with that link tho :)
Perhaps someone can give some more pointers or a short example?

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question