Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Laravel 5.2在Google AppEngine中创建自定义会话?_Php_Laravel_Google App Engine_Session_Session Variables - Fatal编程技术网

Php 如何使用Laravel 5.2在Google AppEngine中创建自定义会话?

Php 如何使用Laravel 5.2在Google AppEngine中创建自定义会话?,php,laravel,google-app-engine,session,session-variables,Php,Laravel,Google App Engine,Session,Session Variables,我在AppEngine的会话中遇到了问题。出于某种原因,每次我登录到我的应用程序时,它每30-60分钟就会把我踢出一次,尽管我在Laravel 5.2的session.php中将生存时间设置为720分钟。我还创建了一个新的会话处理程序。下面是我的档案 app\Extensions\AppEngineStorageSessionHandler.php namespace App\Extensions; class AppEngineStorageSessionHandler implements

我在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;
}
最后,我将此提供程序添加到config\app.php下的提供程序数组中,添加到数组的最末端

'providers' => [
    ....
    App\Providers\SessionServiceProvider::class,
]

我错过了什么?我找了很多很多小时,还没有找到一个可行的解决方案。我还尝试调用了
session_start()在每一页上,什么也没有。任何帮助都将不胜感激。谢谢大家!

您正在使用文件系统进行会话,但App Engine中的实例是短暂的。相反,您应该使用cookie会话或数据库会话

Cookie会话可以通过在您的
app.yaml
中将
SESSION\u驱动程序设置为
Cookie
来实现:

env_variables:
  SESSION_DRIVER: cookie
可以通过以下章节的“设置数据库会话”来实现DatabaseSessions

env_variables:
  SESSION_DRIVER: cookie