New session handler in 2.5

Being stateless, WordPress doesn’t have an in-built way of handling session data. You can use cookies. You can implement PHP Sessions, but both have limitations and some hosts aren’t equipped to deal with them by default.

Early on we decided to adopt a solution based on https://github.com/ericmann/wp-session-manager whereby you have a cookie to identify each user, and have their session data stored in the WP options table. This worked well, and has served us nicely until now. There are however some drawbacks to this solution:

  • It’s hard to clear sessions since the options table contains other data
  • Scalability – Lots of sessions & transients mean slower queries on the options table
  • Performance – as above

The Github issue identifying these problems is here.

For the past few months some of the community, and Gerhard Potgieter who manages the woothemes.com store, have been experimenting with a custom session handler to work around these issues. At it’s core, it is pretty similar to our existing solution. However, it uses custom tables to store the data instead of the WP options table.

woocommerce-large-sessions has actually been running without issue on WooThemes.com a few months now, so we’ve decided it is time to roll that into WooCommerce core.

A slightly modified version of the above has now been merged into 2.5 and is ready to test. If you would like to test the new session handler, just download master from Github.

Note: you may need to reactivate WooCommerce for the new table to be created.

We look forward to your feedback!


Keep yourself in the loop!

Sign up for the WooCommerce developer newsletter:
Hidden
Hidden
Hidden


9 responses to “New session handler in 2.5”

  1. […] For performance and scalability reasons we’re introducing a new session handler which uses custom tables, rather than the WordPress options table. You can read more about this feature here. […]

  2. […] You can read more about this feature here. […]

  3. Abhisek Padhi Avatar
    Abhisek Padhi

    I have been using this settings in my nginx sites-enabled cnfiguration file :-

    location ~ \.php$ {

    set $rt_session “”;
    if ($http_cookie ~* “wp_woocommerce_session_[^=]*=([^%]+)%7C”) {
    set $rt_session wp_woocommerce_session_$1;
    }
    if ($skip_cache = 0 ) {
    more_clear_headers “Set-Cookie*”;
    set $rt_session “”;
    }
    fastcgi_cache_key “$scheme$request_method$host$request_uri$rt_session”;

    try_files $uri =404;


    }

    Do I need to make any modifications, given that the WooCommerce v2.5 (Major) has moved to using Session handler, Or the wp_woocommerce_session is still in use ?
    I will be waiting for some time to be clear on this topic before upgrading Woocommerce in production site.

    1. The cookie setup is identical – its just the data storage location that has changed.

  4. Thanks Mike for the information.

  5. Hi, we have been using https://github.com/kloon/woocommerce-large-sessions for a while on our site. Will this update conflict with it? Should we disable Kloon’s plugin and update woocommerce? What’s the proper way here?

    1. Disable it first, then upgrade. The DB is compatible.

  6. Hi… not sure if this is a bug or a configuration error on my end, but with at least one site I manage, the 2.5.0 update failed to create the woocommerce_sessions data table, resulting in several days of zero orders for the client until I was able to identify the issue and manually create the table.

    1. Do you do a remote update? The updater wouldn’t have triggered until entering the admin area. We’ve cleared this up in 2.5.1 if thats the case.

Leave a Reply

Your email address will not be published. Required fields are marked *