• Resolved OkorieWare

    (@okorieware)


    How do we automatically clear old sessions – sessions older than 24 hours (last active past 24 hours)?

    PS: Either a Settings/Option page, or WordPress code behind, would be acceptable solutions.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hi @okorieware,

    You can change the session lifetime with the pantheon_session_expiration filter. Something like this should do the trick:

    add_filter( 'pantheon_session_expiration', function() { return HOUR_IN_SECONDS * 24; } );

    Hope this helps!

    Thread Starter OkorieWare

    (@okorieware)

    Thank you very much @danielbachhuber

    Thread Starter OkorieWare

    (@okorieware)

    Well,

    I’ve monitored Pantheon Sessions under wp-admin for the past few days, but still find that sessions are not automatically cleared after my set period.

    The following is what I’m using:

    add_action("plugins_loaded", function () {
    	add_filter("pantheon_session_expiration", function() {
    		// todo: 24 hours
    		return HOUR_IN_SECONDS * 6;
    	});

    Can I genuinely clear them automatically?
    I don’t want defunct sessions to be accumulating.

    • This reply was modified 4 years, 1 month ago by OkorieWare. Reason: typo
    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Hi @okorieware,

    The pantheon_session_expiration filter sets the session.cookie_lifetime setting, which:

    specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means “until the browser is closed.” Defaults to 0.

    With the code snippet you shared, a cookie will be valid for 6 hours.

    If this isn’t what you want, can you describe with a bit more detail about what you’re trying to do?

    Thread Starter OkorieWare

    (@okorieware)

    Hi @danielbachhuber,

    What I want is to automatically clear sessions older than 24 hours from Native PHP Sessions database, the one that appears under “wp-admin \ Pantheon Sessions” with the “Clear All” button.

    Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Makes sense, thanks for clarifying ??

    Here’s a code snippet that registers a twice-daily cron job to delete all sessions older than 24 hours: https://gist.github.com/danielbachhuber/c49a6bccfd2fbeab5512c376dd1c5b36

    Thread Starter OkorieWare

    (@okorieware)

    Interesting!

    Thanks again.

    Hi there. I copy the code that you’ve give here. But it does not work.

    add_filter( 'pantheon_session_expiration', function() { return 300; } );

    Am I missing something here?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Clear Old Sessions’ is closed to new replies.