View Full Version : Logged in users optimization (1.0.1)

28 Dec 2002, 22:13
Note to users who have installed Xenon's Optimizing Forumhome v2.0 located here (http://www.vbulletin.org/hacks/index.php?s=&action=showhack&hackid=823) need not install this hack. Furthermore, should you wish to install that hack later on after installing this one, you will need to either uninstall it, or forego the section instructing you to modify the logged in users code.


This simple hack modifies the Logged in users list on the forumhome, reducing queries by one. This is done by knocking off the extra query for guest counting and instead changing the way the while loop that is used for the logged in users list works.

In other words, less queries = win. :)

Versions of vBulletin: 2.2.x
Tested on: 2.2.9
Modifications: File only (no database or template modifications)

Example: http://www.otcentral.com/forum/index.php
Except for the showing of one less query on the query count, you can see that the result is truly unnoticeable. Logged in users operates the same exact way as it does before the hack is made.

Although there's not much that can go wrong with this hack, support will be provided in this thread and by email. Preferrably thread in case someone else runs across the same problem. :)

Update: 12/29/2002 - 0:11

Version 1.0.1 released - Counter was still counting duplicate sessions but not displaying them.

28 Dec 2002, 22:34
nice hack. I'm going to test it on my local server :D

28 Dec 2002, 22:39
looks nice, but i think it could be buggy, because you've thrown out the DISTINCT selection, which wasn't there without reason i think ;).

But we'll see, it's a beta, maybe everything works correct and the distinct was just a devs paranoia ;)

28 Dec 2002, 23:17
DISTINCT is there to make sure no sessions get repeated in the logged in user list. I took that out because no matter how many guests would be there, it would only show up with the first. In its place I put a username token check to make sure the list doesn't already have the user in it.

29 Dec 2002, 01:42
The number of users online on the index is after this mod not the same as the detaild list when you look at the locations and ip. On the index there were 20 and on the detailed list 13! So it looks there is a problem.

29 Dec 2002, 03:48
It seems to work fine on my board. Have you applied any other hacks that affect the logged in users part of your forumhome? Can I get a link to the board you installed it on?

29 Dec 2002, 04:13
Nevermind. I see the problem. The check which prevents duplicate sessions from showing is put outside of the registered user counter. The file is fixed, if you already installed this hack here is the code to move:

if (!substr_count($activeusers_bare,"|||".$username."|||")) {
REPLACE it with this
if (!substr_count($activeusers_bare,"|||".$loggedin['username']."|||")) {

and Move this just BELOW this line:
} else {
and ABOVE this line:

Dean C
29 Dec 2002, 13:03
Wow so we've found another way the vb dev's could reduce queries?

- miSt

29 Dec 2002, 13:22
Not quite yet

It appears for some mods and admins the dupe sessions are still counted and displayed.

Edit: I know what I did wrong. Thank god this is only a beta hack, i would've been dead after the first bug :D

Find this text (note: it's not its own line, there is text after it)

$activeusers_bare .= $username

Change it to this:

$activeusers_bare .= $loggedin['username']

Make sure there's still the . "|||"; after it.

Fixed the text file with the change, but didn't bother updating the version number. :D

29 Dec 2002, 13:26
Surely the vB devs would've thought of this for vB3, I think Kier said vB3's index.php is down to 8 queries... That's not bad considering all the info on it (number of users browsing each forum, last post title, etc)

29 Dec 2002, 16:41
LOL. I implemented the fix locally and fixed the text file here, but forgot to upload the damn thing to my site! http://www.otcentral.com/images/smilies/retard.gif

29 Dec 2002, 19:32
So is this working fine?

29 Dec 2002, 19:34
As far as I can tell, it's good now, really does function like the old currently active users list on the outside like it said originally :D

But still, to be on the safe side, keep a backup of your current index.php so you can revert in case something goes wrong. But I don't see why anything would, there are no template or DB modifications to do.

29 Dec 2002, 19:37
Ok, I'll try it out.

29 Dec 2002, 19:38
I'll be watching this thread :) Post if you notice any problems.

29 Dec 2002, 19:45
I don't think my queries dropped.

29 Dec 2002, 19:47
Do you have microstats installed, or $debug=1; in your config file to confirm this?

Try refreshing (when your session times out, a query is used to create another one, and then it goes back down one query)

29 Dec 2002, 20:26
Thanks Fury!!
It saves me one query!!
Works like a charm. :)

29 Dec 2002, 20:28
fury ;)

No problem, glad it works for you :D

30 Dec 2002, 00:15
I have Microstats installed, and my queries jumped from 35 to 38. I think I might've used the wrong file though. I think I used an index.php that didn't have the caching in it, so the queries rose because of it.

30 Dec 2002, 00:22
Woopsies. :o

30 Dec 2002, 03:54
Nope, I checked it. I used a slightly older index.php from when I first started playing around with the caching hack. I got it back to what it used to be, and it's back to 35. I didn't lose any queries with this hack.

30 Dec 2002, 04:09
Nice job @fury, thanks :)

30 Dec 2002, 14:40
That can't be possible, if you did it right. My hack completely removes a $DB_site->query line related to the logged in users list. Would you feel comfortable sending me your index.php file at dennis@xibase.com so I can check it out?

Thanks, nuno :)

Chris M
30 Dec 2002, 18:43
Looks good;)


01 Jan 2003, 14:30
I believe this hack's ready to come out of beta ;)

Should I just create a new thread or do I ask this one to be moved or what?

(heh, this is my first time ever releasing a hack on vb.org)

01 Jan 2003, 17:03
I think you can start a new Thread in Full Releases.
Put a link to this thread... ;)

01 Jan 2003, 19:00
depends on you :)
if you want i can move the thread to full releases, or you can just close the thread and create a new one in full releases.

just say what you prefer :)

01 Jan 2003, 23:39
Heck yeah, down by one query!

02 Jan 2003, 01:13
@Xenon, me votes move :)

02 Jan 2003, 14:54
ok, i moved it, hope it's ok so :)

02 Jan 2003, 16:16
thumbs up for Xenon :)

02 Jan 2003, 19:28
Thanks a bunch, Xenon :)


02 Jan 2003, 19:37
you're welcome :)

03 Jan 2003, 05:48
i think i will install this regardless but let me tell u the main reason why i think i like this hack. i have some users that like to piss me off when they don't agree w/ what is been done on the site. they use this script that creates multiple duplicate sessions from the same IP and it lags the server to a point that the site becomes inaccessible. will this prevent that from happening or just prevent it from displaying it??? my question is, does this hack block out multiple sessions from someone w/ the same IP?

03 Jan 2003, 13:34
No, it doesn't, it just doesn't count or show the duplicate sessions in the registered user list. Someone who has some experience hacking sessions.php could probably do something like that fairly easily though. The only way I know how adds an extra query to every page.

04 Jan 2003, 00:51
Originally posted by fury
No, it doesn't, it just doesn't count or show the duplicate sessions in the registered user list. Someone who has some experience hacking sessions.php could probably do something like that fairly easily though. The only way I know how adds an extra query to every page.

well i'd sure appreciate it if someone would make that hack for me. these people can cause the board to be inaccessible on a whim.

18 Jan 2003, 13:40
It worked great with my 2.2.7 VB, aswell in combination with the Optimize Forumhome hack! 20 queries!

28 Apr 2003, 08:16
So if I install this, and the optimize forumhome hacks both, neither do the exact same thing and become redundant eh? :)


28 Apr 2003, 12:04
Unless I'm mistaken, the forumhome hack does not incorporate this feature; thus it will not be redundant to install them both.

28 Apr 2003, 16:31
fury, unfortunately you're wrong here.

version 2 of my forumhome optimization hack also incorparates this feature, because i rewrote the online users because of another problem i had.

that way it will be redundant, or even not possible, because the original query isn't there anymore..

29 Apr 2003, 01:02
OK, thanks for the correction. :)

Makes this thread kinda useless huh? :D

29 Apr 2003, 17:13
hmm, if anyone just wants to install that and no more optimizations, then he can use this (ok, i don't know why ;))

but as your thread was before the new version of mine, i'll let it up to you.

if you want to let it be here, it will.
if you want it removed, just tell me, i'll do for ya ;)

29 Apr 2003, 17:18
I think I'll edit the original post with the explanation and a link to the forumhome optimization hack, in case people who have already installed that happen upon this thread. ;)

29 Apr 2003, 17:39
okidokie :)

30 Apr 2003, 00:15
Thanks for the help you two! :D