NYCPHP Meetup

NYPHP.org

[nycphp-talk] "how many users online" PHP solution: sessions or DB?

Hans Zaunere hans at nyphp.org
Tue Nov 4 04:42:29 EST 2003



Phil,

Phil Powell wrote:
> http://codewalkers.com/seecode/75.html
> http://www.webkreator.com/php/concepts/counting-users-online-with-php.html
>  
> The following two URLs illustrate different approaches to the idea of 
> showing "how many
> users online" issue.  I am looking at two different sites where I am 
> looking into implementing
> this type of script; one that has mySQL and one that has no db access of 
> any kind; both use
> PHP 4.1. 
>  
> I (for once) understand what I would need to do to implement it; problem 
> comes in as to which
> solution would be the fastest, most efficient and most secure 
> considering that one of them
> deals with sessions (then there is the cookie issue, but that's another 
> issue altogether,
> see 
> http://www.webkreator.com/php/configuration/php-session-security.html on 
> security issues
> and cookies/sessions).
>  
> What would one best recommend I use: the PHP/mySQL solution (for the 
> non-db issue I would have
> to write complicated XML procedures instead), or sessions?

I think both links you mention are fairly good, and secure.  Using the non-db solution (ie, it counts the number of session files in the tmp directory) would probably be slower.  And, you'd have to take notice of the expire time for the sessions; by default, the php sessions files hang around for quite a while, and you'd be getting false counts.  If possible, I'd go for the mysql method, but it obviously wouldn't work for the non-db site, and it might not fit with the architecture of the existing site.

Thanks,

Hans






More information about the talk mailing list