TextCounter C++ Documentation

Guide to compiling and using the high-performance TextCounter C++ program.

This documentation covers the compiled C++ version. For the Perl version, see TextCounter Perl documentation.

System Requirements

Compilation Steps

  1. Extract and prepare:
    tar xzf textcounter-cpp.tar.gz
    cd textcounter-cpp
  2. Edit the source to set data file path:

    Open textcounter.cpp and edit the DATA_FILE constant:

    const char* DATA_FILE = "/var/www/data/counter.dat";
  3. Compile with file locking support:
    g++ -O2 -o textcounter textcounter.cpp
  4. Create and set permissions for data file:
    touch /var/www/data/counter.dat
    chmod 666 /var/www/data/counter.dat
  5. Install the binary:
    cp textcounter /usr/local/apache/cgi-bin/
    chmod 755 /usr/local/apache/cgi-bin/textcounter

Usage Examples

Use with Server Side Includes:

<!--#exec cgi="/cgi-bin/textcounter"-->

You are visitor number <strong><!--#exec cgi="/cgi-bin/textcounter"--></strong>

<!-- Multiple counters for different pages -->
<!--#exec cgi="/cgi-bin/textcounter?page=home"-->

File Locking

The C++ version implements solid file locking to prevent count corruption under concurrent access. This matters for high-traffic sites where multiple requests may occur simultaneously.

Performance Tips

Troubleshooting

Counter shows 0 or doesn't increment:
Check data file permissions (should be 666) and verify the path in the compiled binary is correct.
Compilation errors:
Ensure g++ is installed and try compiling with -std=c++11 flag for modern C++ features.
Permission denied errors:
The web server user needs write access to both the data file and its directory.
Back to TextCounter C++