I'm using vagrant virtual machine for local PHP development and I noticed that there are session write issues when using vagrant-winnfsd plugin. The plugin serves fine my needs, that's why I don't want to reconfigure vagrant, but rather solve the read/write problem. I don't know the origin of the problem, but it's exactly the same as described here. For me SessionHandler::read()
also takes about 120 seconds to complete on every request.
So as the author suggest, it makes sense to reconfigure session handler to use either RDDBM or Memcache storage. That sounds reasonable, but I don't want to do this in every single project, I just want to configure it once in php.ini since it has session.save_handler
parameter and it can be set to database or memcache there.
I don't mind having one PHP class with all ::read()
, ::write()
and others methods, main thing is having this code in one place.
Is that possible?
UPDATE: I found the reason and really thanks to @Jasper N. Brouwer they were storing in a NFS sync'd folder. The cause was that I did not add prod
environment into AppKernel.php "vagrant" fix. So it used to be:
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test', ''))) {
return '/run/shm/appname/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/run/shm/appname/logs';
}
return parent::getLogDir();
}
and was ok in dev
env, but not in prod
. Should be:
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test', 'prod'))) {
return '/run/shm/appname/cache/' . $this->environment;
}
return parent::getCacheDir();
}
public function getLogDir()
{
if (in_array($this->environment, array('dev', 'test', 'prod'))) {
return '/run/shm/appname/logs';
}
return parent::getLogDir();
}
HOWEVER, just out of curiosity and for easier debugging, since we have now this bounty, I still find the common session save handler for the whole PHP server a nice idea. This may be useful in development if I have to save it into a DB and then can view session data for all projects in realtime in a database using my GUI tool. Maybe, it's possible to do it using auto_prepend_file
setting? And define save hanlder there, but I'm not sure how to disallow override of it later in any project code.