XF 2.0 Increase Online status timeout

Hi guys, first post so go gentle, I've ported over from VB and am just having a little trouble increasing this option above the limited 60 minutes.

I found online how you do it on older version but not on ZF2?

Any help appreciated.

Matt
 
For whatever reason, you still can't do this with XF's default settings. You'll have to edit src/XF/Repository/SessionActivity.php, look for this line and change the value there:

$cutOff = \XF::$time - 3600;

You might also have to put the forum in dev mode and edit the value in your admin - I can't remember offhand if this is really necessary, but just in case. (Or maybe you could just do that and not actually have to edit the sessions file.) You'll get an error every time XF does a file health check, but you can ignore it.
 
Sorry, I think I left something off there. You'd have to also edit this line in sessionactivity.php:

$onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 60;

But like I said, first just try to put the forum in dev mode and see if editing the value in the admin suffices. All I know for sure is that I got it to work. It's been several months, though, so I'm a little fuzzy on everything I edited - I just copy the file contents over after updating.
 
Last edited:
Ive put it into dev mode and set the:
$onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 240;

Then gone into the user setting and tried to amend it there too but it wont take, its refused to go over 60.

Anything else I can do or is it set to 240 mins now as specified in the sessionactivity.php?

The logged in members has not gone up significantly so I assume not and error reporting is highlighting a mis match in the code which is down to the maximum allowed of 60 conflicting with the 240 I've put in the sessionactivity.php
 
These are the relevant bits I've changed:

$onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 1440; (minutes to hours= 24 hours)
}

return $this->db()->fetchRow("
SELECT
SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS total,
SUM(IF(user_id > 0, 1, 0)) AS members,
SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS members (this is "AS guests" by default, so up to you if you want to fudge those numbers. I don't have guests, so....)
FROM xf_session_activity
WHERE view_date >= ?
", $onlineCutOff);
}


And here:

public function pruneExpiredActivityRecords($cutOff = null)
{
if ($cutOff === null)
{
$cutOff = \XF::$time - 86400; (seconds to hours= 24 hours)



Then you have to put your forum in dev mode and edit this in Admin/Options/User options:

198038

I don't know if it's really necessary to change this last value to affect the status timeout, but if you don't you won't be able to save after changing any of the options on that page.


EDIT: Oh yeah, one more thing. You'll probably have to change the highlighted line here too in order to be able to save (by clicking the little "Edit" link you see in the above image):

198040
 
Last edited:
These are the relevant bits I've changed:

$onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 1440; (minutes to hours= 24 hours)
}

return $this->db()->fetchRow("
SELECT
SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS total,
SUM(IF(user_id > 0, 1, 0)) AS members,
SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS members (this is "AS guests" by default, so up to you if you want to fudge those numbers)
FROM xf_session_activity
WHERE view_date >= ?
", $onlineCutOff);
}


And here:

public function pruneExpiredActivityRecords($cutOff = null)
{
if ($cutOff === null)
{
$cutOff = \XF::$time - 86400; (seconds to hours= 24 hours)



Then you have to put your forum in dev mode and edit this in Admin/Options/User options:

View attachment 198038

I don't know if it's really necessary to change this last value to affect the status timeout, but if you don't you won't be able to save after changing any of the options on that page.


EDIT: Oh yeah, one more thing. You'll probably have to change the highlighted line here too in order to be able to save (by clicking the little "Edit" link you see in the above image):

View attachment 198040
You are a legend!
Oh my word. I literally couldn't find how to edit the ACP options as before, when we had the spanner icon..
Enable DEV mode is what was catching me out. I enabled Debug not DEV. :rolleyes:🤦‍♂️
Thank you so much! It's that which I was missing.. what a muppet.
Anyway, seems to be all good. As soon as I enabled dev mode, I finally had the options to edit the user options.
Much appreciated!
 
[...]
You have to put your forum in dev mode and edit this in Admin/Options/User options:

View attachment 198038

I don't know if it's really necessary to change this last value to affect the status timeout, but if you don't you won't be able to save after changing any of the options on that page.


EDIT: Oh yeah, one more thing. You'll probably have to change the highlighted line here too in order to be able to save (by clicking the little "Edit" link you see in the above image):

View attachment 198040

In XF 2.1.1 it is sufficient to execute and save your steps copied from me above. Then set /admin.php?options/groups/users/ to the right Timevalue.
 
Last edited:
Hi All,

1717009433779.webp

I increased the status timeout as above in the admin panel and SessionActivity.php. However, it is not working in reality. I am checking the online users, it is increasing and decreasing during the day. But it should raise for one week if these changes work.

What I am doing wrong?
 
You'll just need to go back over everything, do a double-check, as you must have missed something. Unless maybe you're using a beta version and they changed something. I'm still on 2.2, myself.

Did you put the forum into Developer mode and click the little "Edit" link beneath "Online status timeout," make the appropriate changes there?
 
You'll just need to go back over everything, do a double-check, as you must have missed something. Unless maybe you're using a beta version and they changed something. I'm still on 2.2, myself.

Did you put the forum into Developer mode and click the little "Edit" link beneath "Online status timeout," make the appropriate changes there?
I am using 2.2 version as well. Yes, I enabled the developer mode and changed the maximum of status timeout. I have edited SessionActivity.php also.
 
the only thing, the value in the SessionActivity.php is bigger than admin panel. I don't think so it will be problem but this is the only thing different.
 
@imno007

PHP:
class SessionActivity extends Repository
{
    public function getOnlineCounts($onlineCutOff = null)
    {
        if ($onlineCutOff === null)
        {
            $onlineCutOff = \XF::$time - $this->options()->onlineStatusTimeout * 43200;
        }

        return $this->db()->fetchRow("
            SELECT
                SUM(IF(user_id >= 0 AND robot_key = '', 1, 0)) AS total,
                SUM(IF(user_id > 0, 1, 0)) AS members,
                SUM(IF(user_id = 0 AND robot_key = '', 1, 0)) AS members
            FROM xf_session_activity
            WHERE view_date >= ?
        ", $onlineCutOff);
    }

I set as 43200 minute at above.

PHP:
public function pruneExpiredActivityRecords($cutOff = null)
    {
        if ($cutOff === null)
        {
            $expiration = $this->getDefaultSessionActivityExpiration();
            if (!$expiration)
            {
                return;
            }

            $cutOff = \XF::$time - $expiration;
        }

        $this->db()->delete('xf_session_activity', 'view_date < ?', $cutOff);
    }

How should I update here?
 
Last edited:
Back
Top Bottom