【发布时间】:2018-09-12 02:11:18
【问题描述】:
我在 AppEngine 中的会话遇到问题。出于某种原因,每次我登录到我的应用程序时,它每 30 到 60 分钟就会把我踢出去,即使我在 Laravel 5.2 的 session.php 中将生命周期设置为 720 分钟。我还创建了一个新的会话处理程序。以下是我的文件。
app\Extensions\AppEngineStorageSessionHandler.php
namespace App\Extensions;
class AppEngineStorageSessionHandler implements \SessionHandlerInterface{
private $savePath = '';
public function open($savePath,$sessionName){
$this->savePath = 'http://example.com';
if(!is_dir($this->savePath)){
mkdir($this->savePath,0777);
}
return true;
}
public function close(){
return true;
}
public function read($id){
return (string)@file_get_contents($this->savePath.'/sess_'.$id);
}
public function write($id,$data){
return (file_put_contents($this->savePath.'/sess_'.$id,$data) === false)?false:true;
}
public function destroy($id){
$file = $this->savePath.'/sess_'.$id;
if(file_exists($file)) {
unlink($file);
}
return true;
}
public function gc($maxlifetime){
foreach(glob($this->savePath.'/sess_*') as $file){
if(filemtime($file) + $maxlifetime < time() && file_exists($file)){
unlink($file);
}
}
return true;
}
我为此处理程序创建了一个新的提供程序。
app\Providers\SessionServiceProvider.php
namespace App\Providers;
use App\Extensions\AppEngineStorageSessionHandler;
use Illuminate\Support\ServiceProvider;
use Session;
class SessionServiceProvider extends ServiceProvider{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
Session::extend('gae_session', function($app) {
// Return implementation of SessionHandlerInterface...
return new AppEngineStorageSessionHandler;
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
最后,我将此提供程序添加到 config\app.php 下的 Providers 数组的最末尾。
'providers' => [
....
App\Providers\SessionServiceProvider::class,
]
我错过了什么?我已经搜索了很多很多小时,但没有找到可行的解决方案。我还尝试在每一页上调用session_start();,但什么也没有。任何帮助将不胜感激。谢谢!
【问题讨论】:
标签: php laravel google-app-engine session session-variables