Facebook PHP SDK - getUser()从Facebook注销后返回有效的userId

I'm putting a "Login with Facebook" option in a website and I managed to achieve it quite smoothly. I'm relying in facebook->getUser() method which, according to the documentation, returns the Facebook User ID of the current user, or 0 if there is no logged-in user. However, after logging in, all subsequent calls to getUser() return the userId, even if I go manually to facebook and logout. Seems like the userId is being cached or something. I can see many people with the same issue but still could't find a solution for this. How can I overcome this issue (the website is based in CodeIgniter and I'm referring to this tutorial)?

Copy paste from my website.

    $user = $this->facebook->getUser();

    // We may or may not have this data based on whether the user is logged in.
    //
    // If we have a $user id here, it means we know the user is logged into
    // Facebook, but we don't know if the access token is valid. An access
    // token is invalid if the user logged out of Facebook.
    $profile = null;
    if($user)
    {
        try {
            // Proceed knowing you have a logged in user who's authenticated.
            $profile = $this->facebook->api('/me?fields=id,name,link,email');
        } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }
    }

See how $user goes to null if the API doesn't respond? That's the key. If you don't go through that step, it wont work. getUser will sometimes return an ID even if the user recently logged out.