用户不会离线

So basically I have this script for my server that keeps all the users up to date on my panel for my .net licensing system, but for some reason some of the users don't go offline when they are most definitely not connected to the server.

Basically every time the user checks in( every minute ) it will update their account with the time they checked in. Then I have the following script to check if the user's check in time is 2 minutes behind the time it is now, so then it will set them offline as they haven't checked in, in 2 minutes.

My problem is, it is working for most users, but like 9% of them don't go offline when checking and there seems to be no errors, unless i'm wrong, can anyone help me out in fixing this simple problem?

PHP SCRIPT:

$SQLGetUsers = $odb -> query("SELECT * FROM Account");
while ($getInfo = $SQLGetUsers -> fetch(PDO::FETCH_ASSOC))
{
    $id = $getInfo['id'];
    $lastlogon = $getInfo['lastlogon'];
    $time = time();
    $timeouttime = ($time - 120);
    if ($lastlogon <= $timeouttime) 
    {
        $odb->exec("UPDATE Account SET `online` = '0' WHERE `id` = '$id'");
    }
    $odb->exec("OPTIMIZE TABLE Account");
}

I do know this is a bad script, but it's the only way I personally know of executing this specific command. Thanks to anyone who can help!