CDbHttpSession not working correctly
parsasaei opened this issue · 3 comments
Hi,
I used database session storage approach for using mys sessions,
And I used this article too: slow-db-session-table
So I created YiiSession table in my db with this script:
CREATE TABLE YiiSession (
id char(32) NOT NULL,
expire int(11) unsigned DEFAULT NULL,
data varchar(4096) DEFAULT NULL,
PRIMARY KEY (id),
KEY expire_idx (expire) USING BTREE
) ENGINE=MEMORY DEFAULT CHARSET=utf8;
And my config in config/main.php
:
'session' => [
'class' => 'CDbHttpSession',
'connectionID' => 'db',
'sessionTableName' => 'YiiSession',
'timeout' => 3600 * 24 * 30,
'autoStart' => false,
'autoCreateSessionTable' => false
],
I stores all user cart info session values as an object like this:
Yii::app()->session['user-cart'] = $this->cartInfo;
Issue
There are some issues,
1- Session, after page redirect sometimes no have any value,there is this problem with using CDbHttpSession
and no in session file working approach.
2- Sometimes session stores but unset session not works, and maybe after calling two more time the method clears sessions it works.
unset(Yii::app()->session['user-cart']);
What is the problem?
I don't have any problem with working with session file approach, but db session not working correctly in my codes.
Additional info
Q | A |
---|---|
Yii version | 1.1.23 |
PHP version | 7.4 |
Operating system | ubuntu 20.04 |
Your session table structure is wrong/outdated. Check out CDbHttpSession->createSessionTable
Your session table structure is wrong/outdated. Check out CDbHttpSession->createSessionTable
Now, I dropped my session table and regenerated it with this structure:
CREATE TABLE YiiSession
(
id CHAR(32) PRIMARY KEY,
expire INTEGER,
data BLOB,
KEY expire_idx (expire) USING BTREE
);
But, still my problem is exists.
@parsasaei I have to close this ticket as the issue tracker is meant for clearly reproducable bugs and not for support questions. Please visit https://www.yiiframework.com/community for support options.