-
-
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
session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) #13740
Comments
Do you have permissions allowing your webserver user to access |
Thanks for posting in our issue tracker.
Thanks! This is an automated comment, triggered by adding the label |
Yes. I gave it 777 even though it doesn't work. I have 2.0.8 working on the same machine and PHP config without any issues. |
Well, "failed to write session data" means exactly what it's saying i.e. file could not be written by the user running PHP process. 2.0.8 was ignoring the fact and continue running with empty session. Current version throws this error to warn developer that it's not OK and session, in fact, isn't written. You should check for permissions again and make sure that the user (usually |
Alex,
I checked the folder permissions before I posted this as an issue.
My sessions are stored in MySQL database. sessions doesn't even have to write to the folder in the first place. They should directly read and write in MySQL. I can share my session config if needed pls let me know
Thanks,
Mir Adnan
… On Mar 9, 2017, at 9:38 PM, Alexander Makarov ***@***.***> wrote:
Well, "failed to write session data" means exactly what it's saying i.e. file could not be written by the user running PHP process. 2.0.8 was ignoring the fact and continue running with empty session. Current version throws this error to warn developer that it's not OK and session, in fact, isn't written.
You should check for permissions again and make sure that the user (usually www-data) can actually write to that directory.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Hmm...
But
That doesn't seem to make sense. Do you have right config file loaded? |
Yes. The same config was working absolutely fine with 2.0.8. I upgraded and this issue came up. File common\db\DbSession containsnamespace common\db;
use Yii;
use yii\db\Connection;
use yii\db\Query;
use yii\base\InvalidConfigException;
use yii\di\Instance;
use yii\web\MultiFieldSession;
use yii\web\ErrorHandler;
use yii\db\Exception;
use common\helpers\RequestHandler;
use common\components\BrowserComponent;
class DbSession extends \yii\web\DbSession {
/**
* Device Type 1
*/
const DEVICE_TYPE = 1;
/**
*
* @var type
*/
public $executed = false;
/**
* Session write handler.
* Do not call this method directly.
* @param string $id session ID
* @param string $data session data
* @return boolean whether session write is successful
*/
public function writeSession($id, $data) {
if ($this->executed) {
return $this->executed;
}
$this->executed = true;
// exception must be caught in session write handler
// http://us.php.net/manual/en/function.session-set-save-handler.php
try {
$query = new Query;
$exists = $query->select(['id'])
->from($this->sessionTable)
->where(['id' => $id])
->createCommand($this->db)
->queryScalar();
$fields = $this->composeFields($id, $data);
$fields['ip'] = RequestHandler::getIp();
$fields['device_type'] = self::DEVICE_TYPE;
$fields['device_info'] = BrowserComponent::getBrowser();
if (!empty(Yii::$app->session['user']['id'])) {
$fields['user_id'] = Yii::$app->session['user']['id'];
}
if ($exists === false) {
$this->db->createCommand()
->insert($this->sessionTable, $fields)
->execute();
} else {
unset($fields['id']);
$this->db->createCommand()
->update($this->sessionTable, $fields, ['id' => $id])
->execute();
}
} catch (\Exception $e) {
$exception = ErrorHandler::convertExceptionToString($e);
// its too late to use Yii logging here
error_log($exception);
echo $exception;
return false;
}
return true;
}
} SQL Structure--
-- Table structure for table `system_sessions`
--
CREATE TABLE `system_sessions` (
`id` char(40) NOT NULL,
`user_id` bigint(20) NOT NULL DEFAULT '0',
`ip` varchar(25) DEFAULT NULL,
`expire` int(11) DEFAULT NULL,
`data` longblob,
`device_type` tinyint(4) NOT NULL DEFAULT '0',
`device_identifier` varchar(255) DEFAULT NULL,
`device_info` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `system_sessions`
--
ALTER TABLE `system_sessions`
ADD PRIMARY KEY (`id`),
ADD KEY `user_id` (`user_id`); |
@samdark - It works well if I don't override the |
Looks similar to #9438 with same reason of failure. |
What steps will reproduce the problem?
I had 2.0.8 and I upgraded to 2.0.11
What is the expected result?
It should allow me to browse the app instead it started throwing error
What do you get instead?
session_write_close(): Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/lib/php/session)
Additional info
The text was updated successfully, but these errors were encountered: