XF 1.3 Fatal error: Allowed memory size of ... bytes exhausted, when loading index page.

Terry Love

Member
User sessions seem to be running out of RAM for when the user list is pulled up. Ram is set to 128M by default, but I've since increased it to 256mb RAM by putting ini_set("memory_limit","256m");
in my ".../forums/library/config.php" file.

This feels like a temporary fix. More users in the user list will mean more ram will be required to show member list pages, or members online sections. Is there a fix I can do to tame the high use of RAM this is currently requiring?

Related: The error I receive on the index page, or the member list page.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 93 bytes) in .../forums/library/Zend/Db/Statement/Mysqli.php on line 304
 
Are you sure it's related to online member list? While that will use some amount of additional memory, it shouldn't be anywhere near that.

I would disable all add-ons and see if that makes a difference (at your busy times).
 
Pretty sure, yeah. I modify the Xenforo_Model_Session::getSessionActivityQuickList code to return a bunch of empty arrays and I no longer get the issue. Probably has to do with how it loads every single guest, member, and bot into memory before it starts iterating over anything to get counts. In the code it stated as a comment that it might be a good idea to cache the online members look up data.

Just now I cooked up a solution... Doesn't work exactly like the original method yet, but it does greatly reduce the chance of going over the maximum allowed memory limit.
Basically it uses a count queries to get the counts, and then it selects ONLY members for the list of online members to iterate over. This works better than counting the members in PHP.

Code:
/**
     * Gets a quick list of session activity info, primarily useful for the list of
     * online users with the forum list. This is for testing purposes only.
     *
     * @param array $viewingUser
     * @param array $conditions List of conditions; should probably include cutOff
     * @param array|null $forceInclude Forces the specified user to be included
     *
     * @return array Keys: guests, members, robots, total (all including invisible), records (details of users that can be seen)
     */
    public function getSessionActivityQuickListTest(array $viewingUser, array $conditions = array(), array $forceInclude = null)
    {   
        $result = array(
            "guests" => $this->countSessionActivityRecords(array("userLimit" => "guest")),
            "members" => $this->countSessionActivityRecords(array("userLimit" => "registered")),
            "robots" => $this->countSessionActivityRecords(array("userLimit" => "robot")),
        );
                $result['total'] = $result['guests'] + $result['members'] + $result['robots'];
        $fetchOptions = array(
            'join' => self::FETCH_USER,
            'order' => 'view_date'
        );
                $conditions['userLimit'] = "registered";
                $conditions['getInvisible'] = true;
                $conditions['getUnconfirmed'] = true;
                $result['records'] = $this->getSessionActivityRecords($conditions, $fetchOptions);
               
                $limit = XenForo_Application::get('options')->membersOnlineLimit;
        $totalRecords = count($result['records']);

        // maxiumum user online
        if ($limit == 0 || $totalRecords < $limit)
        {
            $result['limit'] = $totalRecords;
        }
        else
        {
            $result['limit'] = $limit;
        }
                $result['recordsUnseen'] = 0;
                return $result;
    }
 
Last edited:
Top Bottom