• Resolved maycal

    (@maycal)


    Hello. Sessions are not automatically deleted after idle timer is ended.

    Screenshot is here: https://ibb.co/xDQHPtX

    As you can see, the idle timer has expired a long time ago, but sessions was not deleted from the table.

    Could you help me and tell how to fix this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter maycal

    (@maycal)

    The question is still relevant to me

    Plugin Author Pierre Lannoy

    (@pierrelannoy)

    Hello @maycal !

    Once again, sorry for this late answer (I’m on vacation with very limited access to internet).

    As you confirmed by PM your cron is working for posts, I’m assuming it’s the standard WP cron… Could you tell me if Sessions analytics are correctly working (no “holes” in data)?

    Can I ask you too, how many users do you have? And for how long Sessions is installed? Do you have some errors in your PHP logs? Do you have installed some tools (like DecaLog) to collect errors on your site? If so, what are they?

    I will try to continue this discussion as soon as I have internet access (maybe 3-4 days). Thank you for your understanding.

    Pierre

    Thread Starter maycal

    (@maycal)

    The issue was solved by creating a special code that forcibly closes the session after the timer expires (a function that automatically starts in the plugin and forcibly checks sessions for the date of their expiration).

    You need to download this file: https://drive.google.com/file/d/14LjYdKB0VtULmRjcE6S9lwmSBZTNxgQc/view?usp=sharing

    and put it to:

    /wp-content/plugins/sessions/includes/system/ (replace original class-session.php)

    This is a code, that was added into original class-session.php (lines 1025 – 1064):

    public static function try_to_terminate_sessions() {
    		
    		global $wpdb;
    		$cpt   = 0;
    		$limit = 0;
    		$index = 0;
    		$sql   = 'SELECT user_id, meta_value FROM ' . $wpdb->usermeta . " WHERE meta_key='session_tokens' ORDER BY user_id DESC LIMIT " . (int) Option::network_get( 'buffer_limit' );
    		// phpcs:ignore
    		$query = $wpdb->get_results( $sql, ARRAY_A );
    		if ( is_array( $query ) && 0 < count( $query ) ) {
    			if ( $limit > count( $query ) ) {
    				$index = 0;
    			} else {
    				$index += $limit;
    			}
    			foreach ( $query as $row ) {
    				$sessions = $row['meta_value'];
    				if ( ! is_array( $sessions ) && is_string( $sessions ) ) {
    					$sessions = maybe_unserialize( $sessions );
    				}
    				if ( is_array( $sessions ) ) {
    					$cpt += Session::auto_terminate_session( $sessions, (int) $row['user_id'] );
    				}
    			}
    			switch ( $cpt ) {
    				case 0:
    					\DecaLog\Engine::eventsLogger( POSE_SLUG )->debug( 'No session to auto-terminate.' );
    					break;
    				case 1:
    					\DecaLog\Engine::eventsLogger( POSE_SLUG )->notice( sprintf( '%d session auto-terminated.', $cpt ) );
    					break;
    				default:
    					\DecaLog\Engine::eventsLogger( POSE_SLUG )->notice( sprintf( '%d sessions auto-terminated.', $cpt ) );
    					break;
    			}
    		} else {
    			\DecaLog\Engine::eventsLogger( POSE_SLUG )->debug( 'No session to auto-terminate.' );
    			$index = 0;
    		}
    	}

    And call of the fuction (line 952 in modified class-session.php)

    self::try_to_terminate_sessions();

    Tested with sessions version 2.3.0

    • This reply was modified 3 years, 4 months ago by maycal.
    Plugin Author Pierre Lannoy

    (@pierrelannoy)

    Hello @maycal !

    Thanks for this answer (and the solution you’ve found).
    Note doing like that is:

    • only needed if you have something that produce errors in the shutdown hook. Your way to do this is basically the same thing that the Sessions’ zoo-keeper… (see includes/features/class-zookeeper.php);
    • a way to slow-down your site as it will query all user metas for each request at the initialization (with the zoo-keeper, it is done with a small batch size, and in the shutdown hook).

    Nevermind, if it’s working for you, it’s a good news ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘sessions hang (not deleted)’ is closed to new replies.