Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:20:36+00:00 2026-05-26T00:20:36+00:00

I am building a shopping cart using the Yii framework. I have created a

  • 0

I am building a shopping cart using the Yii framework. I have created a cart model to store the items the user adds to the cart, and I’m keeping track of the products that guest shoppers are adding to the cart by using a session_id field that stores the current session.

However, if the shopper abandons the cart or the session simply times out before they proceed to the checkout I find that I have a bunch of records in the cart table that need to be cleaned up.

I was thinking that the best way to do this would be to piggy back on the garbage collection process that Yii uses to clean up the session table, but I’m not sure how to do this, or even if this is the best way.

Am I on the right track here?

If so, how do I go about piggybacking on Yii’s garbage collection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:20:37+00:00Added an answer on May 26, 2026 at 12:20 am

    I don’t know much about PHP’s session garbage collection, so I don’t know if this is a better way to go than a cron job. The little I do know I just learned from Professor Google, and it makes me think relying on the session garbage collection may not be as reliable as you want:

    How do I expire a PHP session after 30 minutes?

    But it could work, I suppose. Kind of clever, actually, if it does. And in this case, you would need to override the gcSession() method in the CDbHttpSession class in the Yii core (assuming, as you say, you are using the database session storage). You can override this method very easily, actually, in your config.php file.

    First, create your new MyCustomHttpSession class which extends CDbHttpSession (drop it in your /components folder probably). Be sure to add your new custom Cart garbage collection to the gcSession() function!

    class MyCustomHttpSession extends CDbHttpSession
    {
      public function gcSession($maxLifetime) {
        /**** ADD YOUR CUSTOM LOGIC HERE ****/
        $sql="DELETE FROM {$this->sessionTableName} WHERE expire<".time();
        $this->getDbConnection()->createCommand($sql)->execute();
        return true;
      }
    }
    

    Then, tell Yii to use your new MyCustomHttpSession class in the components configuration array:

    'components'=>array(
      'session'=>array(
        'class' => 'application.components.MyCustomHttpSession',
        'connectionID' => 'db',
        'timeout'=>14400, // 4 hour session time
      ),
    ),
    

    I did not test this, but it should work just fine. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie backbone question: Context: Building a shopping list with backbone I have a model
I am building a Web Application for shopping cart using ASP.NET and I am
just wondering if there could be any issue building a shopping cart using Backbone.js
We are in the middle of building a shopping cart and are using Virtuemart.
I'm building shopping mall website using Yahoo solution. My products have multiple options which
I'm building a shopping cart page that could potentially contain dozens of separate items.
I am building a shopping cart application for android. My customers already have google
I am currently building a shopping cart for a client but he wants different
i am currently building a custom shopping cart to my website, it has all
I am currently building a new style ecommerce shopping cart to test various scenarios

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.