欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php设置了session存储路径为redis后,php的fpm崩溃了

程序员文章站 2022-04-29 22:15:04
...
redis) {
            $cfg = [
                'scheme' => env('REDIS_SCHEME', 'tcp'),
                'host' => env('REDIS_HOST', '127.0.0.1'),
                'port' => env('REDIS_PORT', 6379)
            ];
            $this->redis = new \Predis\Client($cfg);
        }
    }

    /**
     * Close the session
     * @since 5.4.0
     */
    public function close()
    {
        $this->redis->quit();
        return true;
    }

    /**
     * Destroy a session
     * @since 5.4.0
     */
    public function destroy($session_id)
    {
        $this->connect();
        return $this->redis->del($session_id);
    }

    /**
     * Cleanup old sessions
     * @since 5.4.0
     */
    public function gc($maxlifetime)
    {
        return true;
    }

    /**
     * Initialize session
     * @since 5.4.0
     */
    public function open($save_path, $session_id)
    {
        return true;
    }

    /**
     * Read session data
     * @since 5.4.0
     */
    public function read($session_id)
    {
        $this->connect();
        return $this->redis->get($session_id);
    }

    /**
     * Write session data
     * @since 5.4.0
     */
    public function write($session_id, $session_data)
    {
        $this->connect();
        $expire  =  configure('Ymf.Account.expire');
        if(is_int($expire) && $expire > 0) {
            $result = $this->redis->setex($session_id, $expire, $session_data);
            $re = $result ? 'true' : 'false';
        }else{
            $result = $this->redis->set($session_id, $session_data);
            $re = $result ? 'true' : 'false';
        }
        return $re;
    }
}

这是我的代码,怎么调试哪里出错了

回复内容:

redis) {
            $cfg = [
                'scheme' => env('REDIS_SCHEME', 'tcp'),
                'host' => env('REDIS_HOST', '127.0.0.1'),
                'port' => env('REDIS_PORT', 6379)
            ];
            $this->redis = new \Predis\Client($cfg);
        }
    }

    /**
     * Close the session
     * @since 5.4.0
     */
    public function close()
    {
        $this->redis->quit();
        return true;
    }

    /**
     * Destroy a session
     * @since 5.4.0
     */
    public function destroy($session_id)
    {
        $this->connect();
        return $this->redis->del($session_id);
    }

    /**
     * Cleanup old sessions
     * @since 5.4.0
     */
    public function gc($maxlifetime)
    {
        return true;
    }

    /**
     * Initialize session
     * @since 5.4.0
     */
    public function open($save_path, $session_id)
    {
        return true;
    }

    /**
     * Read session data
     * @since 5.4.0
     */
    public function read($session_id)
    {
        $this->connect();
        return $this->redis->get($session_id);
    }

    /**
     * Write session data
     * @since 5.4.0
     */
    public function write($session_id, $session_data)
    {
        $this->connect();
        $expire  =  configure('Ymf.Account.expire');
        if(is_int($expire) && $expire > 0) {
            $result = $this->redis->setex($session_id, $expire, $session_data);
            $re = $result ? 'true' : 'false';
        }else{
            $result = $this->redis->set($session_id, $session_data);
            $re = $result ? 'true' : 'false';
        }
        return $re;
    }
}

这是我的代码,怎么调试哪里出错了

相关标签: php session