Skip to content
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

[5.x]: session_start(): Unexpected end of serialized data #16859

Open
thupsi opened this issue Mar 10, 2025 · 1 comment
Open

[5.x]: session_start(): Unexpected end of serialized data #16859

thupsi opened this issue Mar 10, 2025 · 1 comment
Labels

Comments

@thupsi
Copy link

thupsi commented Mar 10, 2025

What happened?

Description

I have a project that I'm trying to upgrade from Craft 4 to Craft 5. In some of my templates I use both craft.app.session and the cookies plugin. I'm also fetching data from an external DB following this article. In those templates, I get the following error:

yii\base\ErrorException: session_start(): Unexpected end of serialized data in /var/www/html/vendor/yiisoft/yii2/web/Session.php:150
Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/web/ErrorHandler.php(115): yii\base\ErrorHandler->handleError(8, 'session_start()...', '/var/www/html/v...', 150)
#1 [internal function]: craft\web\ErrorHandler->handleError(8, 'session_start()...', '/var/www/html/v...', 150)
#2 /var/www/html/vendor/yiisoft/yii2/web/Session.php(150): session_start()
#3 /var/www/html/vendor/yiisoft/yii2/web/Session.php(750): yii\web\Session->open()
#4 /var/www/html/vendor/craftcms/cms/src/helpers/Session.php(95): yii\web\Session->has('__duration')
#5 /var/www/html/vendor/craftcms/cms/src/web/User.php(528): craft\helpers\Session::has('__duration')
#6 /var/www/html/vendor/yiisoft/yii2/web/User.php(199): craft\web\User->renewAuthStatus()
#7 /var/www/html/vendor/craftcms/cms/src/web/Application.php(455): yii\web\User->getIdentity()
#8 /var/www/html/vendor/craftcms/cms/src/web/Application.php(112): craft\web\Application->debugBootstrap()
#9 /var/www/html/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#10 /var/www/html/vendor/yiisoft/yii2/base/Application.php(204): yii\base\BaseObject->__construct(Array)
#11 [internal function]: yii\base\Application->__construct(Array)
#12 /var/www/html/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs(Array)
#13 /var/www/html/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#14 /var/www/html/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#15 /var/www/html/vendor/craftcms/cms/src/Craft.php(71): yii\BaseYii::createObject(Array, Array)
#16 /var/www/html/vendor/craftcms/cms/bootstrap/bootstrap.php(343): Craft::createObject(Array)
#17 /var/www/html/vendor/craftcms/cms/bootstrap/web.php(40): require('/var/www/html/v...')
#18 /var/www/html/public/index.php(11): require('/var/www/html/v...')
#19 {main}

Notes:

  • If I reload the page it works.
  • When I re-reload it errors again.
  • If I clear the cache with ctrl+F5 it seems to work for some time... until it doesn't.
  • When devMode is disabled the error is hidden and the page loads just fine.

This is probably my fault because I'm doing some weird things in my templates, so — for now — don't lose too much time looking into this, I'd just like a nudge in the right direction. Do you have any obvious pointers based on the above?

I 'll come back to you with more details to help you reproduce if I'm unable to solve by myself, or I'm more confident it's a Craft bug.

Craft CMS version

5.6.11

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@thupsi thupsi added the bug label Mar 10, 2025
@thupsi
Copy link
Author

thupsi commented Mar 11, 2025

Update: Solved this by switching to Redis for session storage. Feel free to close if you think it's not something that's likely to affect others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant