Support » Plugin: WooCommerce Rejoiner » Remove session_start() Dependency

  • Resolved adamchal

    (@adamchal)


    Recently I noticed hundreds of thousands of empty sessions on our server. I finally traced the culprit to line 15 of class-wc-rejoiner.php:

    class WC_Rejoiner extends WC_Integration {
    
        public function __construct() {
    
            session_start(); // <-- line 15
            $this->sess = session_id();

    It looks like the plugin is creating an empty session just to set a cookie and get a unique token. But, no data is ever saved to the PHP session. The Rejoiner data is saved to a WP _transient_rjcart_[session token] row.

    @madjax: I would like to offer the following alternatives to creating empty PHP native sessions:

    1. Leverage WooCommerce’s internal cart/session to save this Rejoiner data;
    2. Or, if this is not a viable solution, then use setcookie() or wp_setcookie() to create a random cookie to act as your session token. You could also allow these cookie properties (name, domain, ttl, etc.) to be configurable in the plugin settings page.

    Either of these approaches would eliminate the dependency on native PHP sessions and would prevent the creation of thousands of empty sessions.

    I’m happy to assist or provide more clarity if you’d like.

    Thanks,
    Adam

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Jackson

    (@madjax)

    Thanks for the info, I’ll review and update you here.

    Is garbage collection not working on your server?

    adamchal

    (@adamchal)

    Hey @madjax, garbage collection is working, but it’s configured with a 30 day TTL. In that time, we accumulate over 300k empty sessions. We’re using a memcache session store in php.ini, so these empty sessions just waste memory. I recently ran a job that cleared out these empty sessions, but then I realized that I’m breaking your plugin since session_start() will generate a new session/cookie if it is not found in memcache.

    I think using your own cookie with wp-admin configurable options, or piggy-backing on WooCommerce’s internal cart/session should be a better approach.

    adamchal

    (@adamchal)

    Hi @madjax, have you given this any more thought?

    Plugin Author Jackson

    (@madjax)

    Hi @adamchal, sorry lost track of this in the midst of a cross country move. Can you try this release and let me know what you think : https://www.dropbox.com/s/bdvxs3ak6w3q73v/woocommerce-rejoiner.zip?dl=0 Thanks!

    adamchal

    (@adamchal)

    Hey @madjax, this is perfect. Much love for this. Thanks a lot!

    Plugin Author Jackson

    (@madjax)

    @adamchal glad to hear it. Can you report back in a week and let me know if you’re still loving it?

    adamchal

    (@adamchal)

    @madjax, will do.

    Hey @madjax, just following up…this is still working great!

    Plugin Author Jackson

    (@madjax)

    Thanks @adamchal, just committed the changes. Appreciate your report.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.