[5.x]: session_start(): Unexpected end of serialized data
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
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+F5it seems to work for some time... until it doesn't. - When
devModeis 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reported session_start() failure at vendor/yiisoft/yii2/web/Session.php:150 and trace the calls through craft/helpers/Session.php and craft/web/User.php. Reproduce the alternating reload behavior with devMode enabled while isolating the templates using craft.app.session, the cookies plugin, and the external database connection; done means identifying a reliable cause and a verified resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100