-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
error saving sessions #9438
Comments
looks like a server configuration issue. Please make sure your server is configured correctly. If you still think there is a yii issue here, please give more details about where. |
@cebe i know but why yii2 cant implement session_save_path('folder'); for this cases ? and define the config in the config.php ? and yes is the server im trying contact the support |
as far as I see you are using DbSession, so how is |
'session' => [
'class' => 'yii\web\DbSession',
'readCallback' => function ($fields) {
return [
'expireDate' => Yii::$app->formatter->asDate($fields['expire']),
];
},
'writeCallback' => function ($session) {
return [
'user_id' => Yii::$app->user->id,
'ip' => $_SERVER['REMOTE_ADDR'],
'is_trusted' => $session->get('is_trusted', false),
'controllerCurrent' => Yii::$app->requestedAction->controller->id,
'actionCurrent' => Yii::$app->requestedAction->id,
'pageCurrent' => Yii::$app->id,
'is_guest' => Yii::$app->user->isGuest
];
}
], when i use write and read callbacks, this save the session file in the /temp and in my localhost work good, but in this remote i get the error and cant log-in, in this case is true i need call the datacenter, but if yii2 can provide the parameter for change this folder i think this will be a good solution the session_save_path('folder'); is a method php for change the folder |
@cebe thx for open this, if can provide the option for define a custom path for save the session in the common\config.php etc a additional param like $sessionPath etc in the hosting is /home/user/temp/ and the php when you try get the path get /temp/ u.u and of course error |
the actual issue here is, that the DbSession class should never try to store a session file somewhere on the disk. I reopened this primarily as a bug report. |
that will be true :S i tryed too, change 2 time the path in the web/index.php [16-Aug-2015 21:46:18 UTC] PHP Fatal error: Uncaught exception 'yii\base\ErrorException' with message 'Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/home/bluegerc/temp/)' in Unknown:0 [16-Aug-2015 21:47:40 UTC] PHP Fatal error: Uncaught exception 'yii\base\ErrorException' with message 'Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/home/bluegerc/public_html/temp/)' in Unknown:0 |
@cebe a question i will need wait the 2.0.7 for use this ? :/ |
there is not even a fix for it so I can not tell you when it will be fixed. |
i think the problem is in the yii\web\session the base class of the dbsession |
@samdark i hosted this in a remote server, and in the logs i receive this error, and i cant login, when i comment the session configuration in the common config.php this work again. |
I've solved putting
Otherwise calling \Yii::$app->user->isGuest I also get that error |
@FabrizioCaldarelli the problem is, this class create a file in the server, and in webservers i get errors :/ |
What class are you talking about? I refer to this configuration: 'session' => [
'class' => 'yii\web\DbSession',
'readCallback' => function ($fields) {
return [
'expireDate' => Yii::$app->formatter->asDate($fields['expire']),
];
},
'writeCallback' => function ($session) {
return [
'user_id' => Yii::$app->user->id,
'ip' => $_SERVER['REMOTE_ADDR'],
'is_trusted' => $session->get('is_trusted', false),
'controllerCurrent' => Yii::$app->requestedAction->controller->id,
'actionCurrent' => Yii::$app->requestedAction->id,
'pageCurrent' => Yii::$app->id,
'is_guest' => (\Yii::$app->user->getIdentity(false) == null)
];
}
] |
@FabrizioCaldarelli the class DbSessions |
Hi @spiritdead |
@andrewnester yeah is this <?php
return [
'language' => 'es-ES',
'name' => 'Proyect Cat',
'timeZone' => 'Europe/Berlin',
'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',
'modules' => [
'gridview' => [
'class' => '\kartik\grid\Module'
]
],
'components' => [
'cache' => [
'class' => 'yii\caching\FileCache',
],
'slimApi' =>[
'class' => 'common\components\SlimApi',
'apiKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'userID' => 'xxxx'
],
'session' => [
'class' => 'yii\web\DbSession',
'readCallback' => function ($fields) {
return [
'expireDate' => Yii::$app->formatter->asDate($fields['expire']),
];
},
'writeCallback' => function ($session) {
return [
'user_id' => Yii::$app->user->id,
'ip' => $_SERVER['REMOTE_ADDR'],
'is_trusted' => $session->get('is_trusted', false),
'controllerCurrent' => Yii::$app->requestedAction->controller->id,
'actionCurrent' => Yii::$app->requestedAction->id,
'pageCurrent' => Yii::$app->id,
'is_guest' => Yii::$app->user->isGuest
];
}
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
'db'=>[
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning'],
'except'=>['yii\web\HttpException', 'yii\i18n\I18N'],
'prefix'=>function(){
$url = !Yii::$app->request->isConsoleRequest ? Yii::$app->request->getUrl() : null;
$user = Yii::$app->has('user', true) ? Yii::$app->user : null;
$userName = $user ? $user->identity->username : '-';
return sprintf('[%s][%s][%s]',$userName, Yii::$app->id, $url);
},
'logVars'=>[],
'logTable'=>'log'
]
],
],
'urlManager'=>[
//'urlFormat'=>'path',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules'=>[
'<controller:[a-z\-]+>/<id:\d+>'=>'<controller>/view',
'<controller:[a-z\-]+>/<action:[a-z\-]+>/<id:\d+>'=>'<controller>/<action>',
'<controller:[a-z\-]+>/<action:[a-z\-]+>'=>'<controller>/<action>',
],
],
'urlManagerUpload' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/uploads/',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'urlManagerBase' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'urlManagerFrontToBack' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/backend',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
'urlManagerBackToFront' => [
'class' => 'yii\web\urlManager',
'baseUrl' => '/frontend',
'enablePrettyUrl' => true,
'showScriptName' => false,
]
],
]; |
Can't reproduce it. |
@andrewnester is in shared servers, in the localhost work good, but the problem is, if i use dbsession why this write a file in the temp (session file) ? |
@spiritdead are you sure you have session table in your database on your hosted server? and could you please attach your Yii log file, it will help to find out what's wrong, because I can reproduce error neither on localhost or on hosted server. |
@andrewnester i added the migration of the table session of course, but this report is a little old and i use now other server :/ |
I I've solved this problem by overriding close() method in a subclass of DbSession like this: |
@mhd-shf is your session properly written with empty |
@samdark Yes, I have no problem with that. maybe this is specific to my project that every thing is ok. |
doesn't work. But I have full log now. |
Thanks for logs. It's, indeed #9438 (comment) |
I have the same problem with messages in my nginx error log:
app config has the following: 'session' => [
'class' => 'yii\web\DbSession',
'sessionTable' => 'user_http_session',
'writeCallback' => function ($session) {
return [
'userId' => Yii::$app->getUser()->getId(),
];
},
'name' => 'sid',
'timeout' => 7200,
], Php version 7.0.8, Yii 2.0.13 Does anyone know how to fix it? |
Yes. 'userId' => Yii::$app->getUser() ? Yii::$app->getUser()->getId() : null, // or if you have not null, use an empty string or 0 |
Unfortunally it's still there:
|
What if you'll comment out |
no, no errors. Then I comment writeCallback no errors appears. |
Have the same. And my new friend after 2.0.13:
With callback like this:
|
Also I have this #13212 issue too. Do you think it may be connected? |
Duplicate entry is #13212. |
So, what's the problem with this issue (error saving sassions with writeCallback) and how to fix it is unclear, right? |
Yes. It's totally mysterious. |
I stumbled upon this error too when using DB session storage and here's what I found:
The error should be reproducible by clicking on captcha image and configured writeCallback custom fields e.g.
The issue could be solved preparing session custom fields before closing the session (before executing |
@lubosdz am I correct that it's a custom write callback issue rather than framework issue? |
@samdark No, I believe it's a framework issue - wrong workflow when closing the database session. Custom database session fields should be populated earlier than the session is closed. |
@lubosdz since you're on it, can you handle a pull request? |
hi all, im using the new version of the yii2 2.0.6 but i have this problem
i get this Error
[16-Aug-2015 19:18:46 UTC] PHP Fatal error: Uncaught exception 'yii\base\ErrorException' with message 'Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/tmp)' in Unknown:0
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'Unknown: Failed...', 'Unknown', 0, Array)
#1 {main}
thrown in Unknown on line 0
and is because i use this configuration
in the common.php
in the localhost work Perfectly but in the remote i get the error
any have idea how can solve this ?
The text was updated successfully, but these errors were encountered: