PHPackages                             itxiao6/session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. itxiao6/session

ActiveLibrary[File &amp; Storage](/categories/file-storage)

itxiao6/session
===============

重写了PHP自带的 SESSION 机制，存储介质支持:本地模式、Memcache、Redis、Mamcached、Xcache,php运行模式支持:LAMP、LNMP、SWOOLE

1.0.0.1(8y ago)109146MITPHP &gt;=5.6.0

Since Jul 20Compare

[ Source](https://github.com/itxiao6/session)[ Packagist](https://packagist.org/packages/itxiao6/session)[ Docs](http://github.com/itxiao6/session)[ RSS](/packages/itxiao6-session/feed)WikiDiscussions Synced 2w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

session
=======

[](#session)

##### 重写了PHP自带的 SESSION 机制，存储介质支持:本地模式、Memcache、Redis、Mamcached、Xcache,php运行模式支持:LAMP、LNMP、SWOOLE

[](#重写了php自带的-session-机制存储介质支持本地模式memcacheredismamcachedxcachephp运行模式支持lamplnmpswoole)

1.引入入口 &amp;&amp; 获取实例
----------------------

[](#1引入入口--获取实例)

```
use \Itxiao6\Session\SessionManager;
$session = \Itxiao6\Session\SessionManager::getSessionInterface();
```

2.设置驱动
------

[](#2设置驱动)

### 1.本地存储方式(默认)

[](#1本地存储方式默认)

```
$session -> set_deiver(new \Doctrine\Common\Cache\FilesystemCache(__DIR__.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR));
```

### 2.Redis 驱动

[](#2redis-驱动)

```
$redis = new \Redis();
$redis->connect('127.0.0.1', 6319);
$cacheDriver = new \Doctrine\Common\Cache\RedisCache();
$cacheDriver->setRedis($redis);

$session -> set_deiver($cacheDriver);
```

### 3.Memcache 驱动

[](#3memcache-驱动)

```
$memcache = new \Memcache();
$memcache->connect('127.0.0.1', 11211);

$cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
$cacheDriver->setMemcache($memcache);
$session -> set_deiver($cacheDriver);
```

### 4.Memcached 驱动

[](#4memcached-驱动)

```
$memcached = new \Memcached();
$memcached->addServer($cacheConfig['Mamcached']['host'], $cacheConfig['Mamcached']['port']);

$cacheDriver = new \Doctrine\Common\Cache\MemcachedCache();
$cacheDriver->setMemcached($memcached);
$session -> set_deiver($cacheDriver);
```

### 5.Xcache 驱动

[](#5xcache-驱动)

```
$session -> set_deiver(new \Doctrine\Common\Cache\XcacheCache());
```

### 6.传入配置

[](#6传入配置)

```
$session -> set_config(new \Itxiao6\Session\Tools\Config([
    'session_name'=>'PHPSESSION',
    'session_path'=>'/',
    'session_id_length'=>32,
    'session_id_type'=>1,
    'session_storage_prefix'=>'itxiao6_session_',
    // 默认有效期一天
    'session_expire'=>3600*24,
]));
```

### 7.启动会话

[](#7启动会话)

```
try{
    // 启动会话
    $session -> start();
}catch (\Throwable $exception){
    // 打印错误
    var_dump($exception);
}
```

### 8.设置值

[](#8设置值)

```
$session -> session() -> set('name','戒尺');
```

### 9.设置值

[](#9设置值)

```
echo $session -> session() -> get('name');
```

#### 附录1

[](#附录1)

SWOOLE 模式使用方式 操作和 驱动和上文使用方法一样，唯一的区别就是 步骤使用1的时候调用的"getSessionInterface" 改为"getSwooleSessionInterface" 并且传入 $request 和 $response

```
// 创建http server
$http = new \swoole_http_server('0.0.0.0', 9501, SWOOLE_BASE);
// 监听request 事件
$http->on('request', function(\swoole_http_request $request, \swoole_http_response $response){
    /**
     * 获取Swoole 会话
     */
    $session = \Itxiao6\Session\SessionManager::getSwooleSessionInterface($request,$response);

    /**
     * 设置驱动（文件驱动）
     */
    $session -> set_deiver(new \Doctrine\Common\Cache\FilesystemCache(__DIR__.DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR));
    /**
     * 设置配置实例
     */
    $session -> set_config(new \Itxiao6\Session\Tools\Config());
    /**
     * 启动会话
     */
    try{
        $session -> start();
    }catch (\Throwable $exception){
        var_dump($exception);
    }
    /**
     * 设置一个值 到session 里
     */
    $session -> session() -> set('user_info',['nickname'=>'戒尺','phone'=>'15538147923','sub'=>['id'=>1]]) -> save();
    /**
     * 获取session 里的一个值
     */
    $response -> write(json_encode($session -> session() -> get('user_info')));
    /**
     * 结束请求
     */
    $response -> end();
});
/**
 * 启动http server
 */
$http -> start();
```

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2948d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4aa333e293f1a1ac60afd39e0c6f3463404df4d6e2ff11bff698c868826aab18?d=identicon)[itxiao6](/maintainers/itxiao6)

---

Tags

validationfilesessionMinkernel

### Embed Badge

![Health badge](/badges/itxiao6-session/health.svg)

```
[![Health](https://phpackages.com/badges/itxiao6-session/health.svg)](https://phpackages.com/packages/itxiao6-session)
```

###  Alternatives

[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.7k293.8M1.1k](/packages/league-flysystem-aws-s3-v3)[league/flysystem-memory

In-memory filesystem adapter for Flysystem.

8838.8M318](/packages/league-flysystem-memory)[league/flysystem-async-aws-s3

AsyncAws S3 filesystem adapter for Flysystem.

3012.8M50](/packages/league-flysystem-async-aws-s3)[delight-im/file-upload

Simple and convenient file uploads — secure by default

6811.1k2](/packages/delight-im-file-upload)[contao-community-alliance/dc-general

Universal data container for Contao

1581.4k93](/packages/contao-community-alliance-dc-general)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
