src/UI/Output.php
public static function handleHeartBeat($cookie)
    {
        global $CFG;

        self::headerJson();

        session_start();
        $session_object = null;

        // TODO: Make sure to do the right thing with the session eventially

        // See how long since the last update of the activity time
        $now = time();
        $seconds = $now - LTIX::wrapped_session_get($session_object, 'LAST_ACTIVITY', $now);
        LTIX::wrapped_session_put($session_object, 'LAST_ACTIVITY', $now); // update last activity time stamp

        // Count the successive heartbeats without a request/response cycle
        $count = LTIX::wrapped_session_get($session_object, 'HEARTBEAT_COUNT', 0);
        $count++;
        LTIX::wrapped_session_put($session_object, 'HEARTBEAT_COUNT', $count);

        if ( $count > 10 && ( $count % 100 ) == 0 ) {
            error_log("Heartbeat.php ".session_id().' '.$count);
        }

        $retval = array("success" => true, "seconds" => $seconds,
                "now" => $now, "count" => $count, "cookie" => $cookie,
                "id" => session_id());
        $lti = LTIX::wrapped_session_get($session_object, 'lti');
        $retval['lti'] = is_array($lti) && U::get($lti, 'key_id');
        $retval['sessionlifetime'] = $CFG->sessionlifetime;
        return $retval;
    }
public static function handleHeartBeat($cookie)
    {
        global $CFG;

        self::headerJson();

        session_start();
        $session_object = null;

        // TODO: Make sure to do the right thing with the session eventially

        // See how long since the last update of the activity time
        $now = time();
        $seconds = $now - LTIX::wrapped_session_get($session_object, 'LAST_ACTIVITY', $now);
        LTIX::wrapped_session_put($session_object, 'LAST_ACTIVITY', $now); // update last activity time stamp

        // Count the successive heartbeats without a request/response cycle
        $count = LTIX::wrapped_session_get($session_object, 'HEARTBEAT_COUNT', 0);
        $count++;
        LTIX::wrapped_session_put($session_object, 'HEARTBEAT_COUNT', $count);

        if ( $count > 10 && ( $count % 100 ) == 0 ) {
            error_log("Heartbeat.php ".session_id().' '.$count);
        }

        $retval = array("success" => true, "seconds" => $seconds,
                "now" => $now, "count" => $count, "cookie" => $cookie,
                "id" => session_id());
        $lti = LTIX::wrapped_session_get($session_object, 'lti');
        $retval['lti'] = is_array($lti) && U::get($lti, 'key_id');
        $retval['sessionlifetime'] = $CFG->sessionlifetime;
        return $retval;
    }
public static function handleHeartBeat ( $ cookie ) { global $ CFG ; self :: headerJson ( ) ; session_start ( ) ; $ session_object = null ; // TODO: Make sure to do the right thing with the session eventially // See how long since the last update of the activity time $ now = time ( ) ; $ seconds = $ now - LTIX :: wrapped_session_get ( $ session_object , 'LAST_ACTIVITY' , $ now ) ; LTIX :: wrapped_session_put ( $ session_object , 'LAST_ACTIVITY' , $ now ) ; // update last activity time stamp // Count the successive heartbeats without a request/response cycle $ count = LTIX :: wrapped_session_get ( $ session_object , 'HEARTBEAT_COUNT' , 0 ) ; $ count ++ ; LTIX :: wrapped_session_put ( $ session_object , 'HEARTBEAT_COUNT' , $ count ) ; if ( $ count > 10 && ( $ count % 100 ) == 0 ) { error_log ( "Heartbeat.php " . session_id ( ) . ' ' . $ count ) ; } $ retval = array ( "success" => true , "seconds" => $ seconds , "now" => $ now , "count" => $ count , "cookie" => $ cookie , "id" => session_id ( ) ) ; $ lti = LTIX :: wrapped_session_get ( $ session_object , 'lti' ) ; $ retval [ 'lti' ] = is_array ( $ lti ) && U :: get ( $ lti , 'key_id' ) ; $ retval [ 'sessionlifetime' ] = $ CFG -> sessionlifetime ; return $ retval ; }
Handle the heartbeat calls. This is UI code basically.

Make sure when you call this, you have handled whether
the session is cookie based or not and included config.php
appropriately

if ( isset($_GET[session_name()]) ) {
$cookie = false;
} else {
define('COOKIE_SESSION', true);
$cookie = true;
}

require_once "../config.php";

\Tsugi\UI\Output::handleHeartBeat($cookie);
Handle the heartbeat calls . This is UI code basically .