Hello,
This code must be used as include in some other script. It not need to show information it needs to be executed only.
Example:
When script is included on index.php (not recommended) and someone open website the script will be executed and will detect afk user if in the database information is changed.
I recommend to put (include) in ranking page, because this will slow page when is executed.
(important)EDIT: This script working only when someone access the page of it. Must be in place where will be executed.