When I was writing my hit counter function I thought about this, so I
setup a destructor and the first time I ran the program it hit the
constructor and then did its thing and called the destructor, so when
you suggested this, my first thought was this will not work, but I could
not image that you would suggest it if it was not true, and in fact I
rethought it out and figured this is the way it should work, so I went
to test it again, and it did the same thing, so I thought I was right,
then I thought, wait a minute, and I tried it again, and it worked that
way, so now I know, the first time in a debug session might do this, but
all subsequent calls will not, a little research and it seems Qt has
known about this issue, but I did not, not sure anyone else has seen
this behavior or not, but I duplicated it twice now, but that is using
the debugger and should not effect the service, but lead me to believe
the life time of the thread call was short, but now I see its not, which
makes a lot more sense to me know, so I thought I would mention this.
I already do all the work in my Hit Counter, I store the IP, and can do
a UNIQUE select, so all I need to do is delete the record on destructor,
my guess is that if I restart the service, I should set a variable to
init the database, then empty the database, and the reconnects will
populate it again, so the start up is always fresh.
This will work great, way to easy, thanks.
Thanks
On Fri, 2014-11-21 at 16:25 +0000, Nagaev Boris wrote:
> Hello,
>
> I use the following tricks.
>
> For simple (non-unique, not logged-in) online users number, you can
> use the following trick:
>
> 1. create global variable (yes, I know, it is FOOO), initialize it
> with 0. Protect this variable with boost::mutex.
> 2. increase it in the constructor of your application class
> 3. decrease it in destructor of your application class
>
> If you want the number of unique users... Let me identify users by the
> following string: IP + UA, where IP is IP-address, UA is User-Agent
> and "+" is string concatenation. You can get both of IP and UA from
> WEnvironment. Create global map<string, int>, protected by a mutex.
> Key of this map is IP + UA and value is the number of sessions sharing
> this identifier (probably they all are managed by single user).
> Increase this value in constructor of the application class, decrease
> it in the destructor. Delete key from the map if the value is 0
> (.erase(key)). So size of this map (.size()) is actually the number of
> users online.
>
> For logged-in users you can use the same approach, but use username as
> key instead of IP + UA.
>
>
> Best regards,
> Boris Nagaev
>
>
> On Fri, Nov 21, 2014 at 3:30 PM, Jeffrey Scott Flesher Gmail
> <jeffrey.scott.fles...@gmail.com> wrote:
> > How do you return the number of users online, I need this for a users online
> > feature, also they need to be unique, and is there a way to find their users
> > name if they are logged in?
> >
> > Thanks
> >
> > ------------------------------------------------------------------------------
> > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> > from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> > with Interactivity, Sharing, Native Excel Exports, App Integration & more
> > Get technology previously reserved for billion-dollar corporations, FREE
> > http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> > _______________________________________________
> > witty-interest mailing list
> > witty-interest@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/witty-interest
> >
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> witty-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest