public static function write_close() {
        global $PERF;

        if (self::$sessionactive) {
            // Grab the time when session lock is released.
            $PERF->sessionlock['released'] = microtime(true);
            if (!empty($PERF->sessionlock['gained'])) {
                $PERF->sessionlock['held'] = $PERF->sessionlock['released'] - $PERF->sessionlock['gained'];
            }
            $PERF->sessionlock['url'] = me();
            self::update_recent_session_locks($PERF->sessionlock);
            self::sessionlock_debugging();
        }

        if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
            // More control over whether session data
            // is persisted or not.
            if (self::$sessionactive && session_id()) {
                // Write session and release lock only if
                // indication session start was clean.
                session_write_close();
            } else {
                // Otherwise, if possibile lock exists want
                // to clear it, but do not write session.
                @session_abort();
            }
        } else {
            // Any indication session was started, attempt
            // to close it.
            if (self::$sessionactive || session_id()) {
                session_write_close();
            }
        }
        self::$sessionactive = false;
    }