Link to home
Start Free TrialLog in
Avatar of Aheib
Aheib

asked on

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

hello,

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
Avatar of Aheib
Aheib

ASKER

points increased to 175.

Maybe I have more luck asking in the c++ section?
ASKER CERTIFIED SOLUTION
Avatar of MatrixDud
MatrixDud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aheib

ASKER

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?