-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Confirm that wp_session garbage collection is working correctly #2031
Comments
@pippinsplugins Did you find out of the cron is being run? We just had a report of this as well. |
As far as I can tell it's running. |
Seems this still isn't working. I still see reports of thousands upon thousands of rows in wp_options. |
Is it the standard transient cron that's supposed to run or something else registered by the sessions class? |
WP Session doesn't use transients. This is what is supposed to run: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/includes/libraries/wp-session.php#L118 |
Here's the query count for wp-push :/ deff something going on: |
I think the issue is related to the option_value...check this one entry out: The timestamp on that: 2778971534 is GMT: Wed, 23 Jan 2058 00:32:14 GMT |
Whoa, so looks like the expiration date is getting set really far in the future. |
… save a ton of DB writes. #2031
I just discovered that we were modifying the expiration time but not the expiration variant. This is how Eric explains the two values: /**
* Set both the expiration time and the expiration variant.
*
* If the current time is below the variant, we don't update the session's expiration time. If it's
* greater than the variant, then we update the expiration time in the database. This prevents
* writing to the database on every page load for active sessions and only updates the expiration
* time if we're nearing when the session actually expires.
*
* By default, the expiration time is set to 30 minutes.
* By default, the expiration variant is set to 24 minutes.
*
* As a result, the session expiration time - at a maximum - will only be written to the database once
* every 24 minutes. After 30 minutes, the session will have been expired. No cookie will be sent by
* the browser, and the old session will be queued for deletion by the garbage collector.
*
* @uses apply_filters Calls `wp_session_expiration_variant` to get the max update window for session data.
* @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions.
*/
protected function set_expiration() {
$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
} We had the expiration set to 24 hours but the variant was still set to 24 minutes. |
@cklosowski I just confirmed the expiration bug as well. I created a brand new session and the expiration was also set to 2058. |
Found it! WP Session sets the expiration like this: protected function set_expiration() {
$this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 );
$this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 );
} We modify the expiration to be 24/23 hours by doing this: add_filter( 'wp_session_expiration_variant', array( $this, 'set_expiration_variant_time' ), 99999 );
add_filter( 'wp_session_expiration', array( $this, 'set_expiration_time' ), 99999 );
.
.
.
.
/**
* Force the cookie expiration variant time to 23 hours
*
* @access public
* @since 2.0
* @param int $exp Default expiration (1 hour)
* @return int
*/
public function set_expiration_variant_time( $exp ) {
return current_time( 'timestamp' ) + ( 30 * 60 * 23 );
}
/**
* Force the cookie expiration time to 24 hours
*
* @access public
* @since 1.9
* @param int $exp Default expiration (1 hour)
* @return int
*/
public function set_expiration_time( $exp ) {
return current_time( 'timestamp' ) + ( 30 * 60 * 24 );
} WP Session takes |
This bug has resulted in a TON of session rows not getting properly cleared out, which can have some significant impacts on performance for some sites. I think we should do our best to clear these out during the EDD 2.0 upgrade routine. My proposal is that we run an SQL query to delete all sessions that have an expiration less than May 28, 2058 (a day or two before EDD 2.0 goes out). Unless someone has manually modified the session expiration dates (I'm pretty sure no one has), all recently set sessions (over the last few months) will have an expiration date of 2058. As long as we don't delete any session created 24 hours before the upgrade routine, it shouldn't cause any issues. I just ran a quick test on the EDD site to see how many session rows there are that have an expiration less than May 15, 2058: SELECT * FROM `edd_options` WHERE option_name LIKE '_wp_session_expires_%' AND option_value+0 < 2788703418 There were |
This seems to do the trick nicely: $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%' AND option_value+0 < 2789308218" ); |
Closing as fixed. If there are any concerns or issues, please re-open. |
I suck and failed to actually fix the expirations dates :P |
Nevermind, it was due to having an old cookie still stored. |
I think the upgrade function needs to delete options that are > some value, not <. |
@bdurette Just as a heads up, we created a plugin to help with this recently: It does 3 types of cleanup. |
hello guys, please can anyone help me! _wp_session_expires_71d531600d0bdfdde3f08b1f580c5c7b_wp_session_9998b4cdeb00519b1bced28c43702bef how can I solved this issue, I highly appreciate any help there.. |
@ghinaaltal you can use PHP sessions instead by adding this to your wp-config.php:
The session rows should be automatically deleted each day when the expire. If that is not happening, please make sure your wp-cron is working properly. |
@pippinsplugins thank you I will try adding define( 'EDD_USE_PHP_SESSIONS', true ); to wp_config file.. Also it seems that wp_session_garbage_collection cron job is not working properly, how can I fix that please?? Thanks in advanced. |
It seems that the wp_session garbage collection isn't working correctly. I've seen numerous reports of sites having thousands and thousands, or millions even, rows in wp_options related to wp_session.
Every wp_session row should expire and get automatically cleaned out via a cron job that runs twice a day. As far as I can tell, however, the cron is never firing.
The text was updated successfully, but these errors were encountered: