PHPackages                             caichuanhai/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. caichuanhai/session

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

caichuanhai/session
===================

caichuanhai session lib

v1.01(6y ago)116MITPHP

Since May 24Pushed 6y ago1 watchersCompare

[ Source](https://github.com/caichuanhai/Session)[ Packagist](https://packagist.org/packages/caichuanhai/session)[ RSS](/packages/caichuanhai-session/feed)WikiDiscussions master Synced 3d ago

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

Session
=======

[](#session)

关于
--

[](#关于)

一个普通的php session类库，依赖于`phpfastcache/phpfastcache`，所以驱动支持files,redis,predis,memcache,memcached,mongodb,xcache,apc,cookie。

> 强烈不建议使用cookie，非常不安全

安装
--

[](#安装)

```
composer require caichuanhai/session

```

使用
--

[](#使用)

```
require_once path/to/vendor/autoload.php;
use caichuanhai\session;
$session = new session([$config]);
```

$config为SESSION配置数组，可不传则使用默认值，默认值如下

```
array(
		'session_name' => 'CCHSESSION',
		'session_path' => '/',
		'session_match_ip' => false,
		'session_expire' => 3600*24
	)
```

#### 设置单个SESSION配置的值

[](#设置单个session配置的值)

```
$session->setConfig($name, $value);
```

#### 获取配置值

[](#获取配置值)

```
$session->getConfig([$name]);
```

若`$name`不传则获取所有配置，若获取配置不存在则返回`NULL`

#### 设置驱动

[](#设置驱动)

1. 使用redis驱动，需要安装redis扩展才能使用

```
$session->setDriver('redis', $config);
//$config配置为
$config = array(
	'host' => '127.0.0.1',
	'port' => 6379,
	'password' => null,
	'database' => null
)
```

2. 使用predis驱动，此驱动不需安装redis扩展，直接使用predis类库

```
$session->setDriver('predis', $config);
//$config配置为
$config = array(
		'host' => '127.0.0.1',
		'port' => 6379,
		'password' => null,
		'database' => null
)
```

3. 使用memcache驱动，需要安装memcache扩展才能使用

```
$session->setDriver('memcache', $config);
//$config配置为
$config = array(
		'host' => '127.0.0.1',
		'port' => 11211,
		//'sasl_user' => false,
		//'sasl_password' => false
)
```

4. 使用memcached驱动，此驱动不需安装memcached扩展，直接使用memcached类库

```
$session->setDriver('memcached', $config);
//$config配置为
$config = array(
		'host' => '127.0.0.1',
		'port' => 11211,
		//'sasl_user' => false,
		//'sasl_password' => false
)
```

5. 使用mongodb驱动

```
$session->setDriver('mongodb', $config);
//$config配置为
$config = array(
		'host' => '127.0.0.1',
		'port' => 27017,
		'username' => '',
		'password' => '',
		'timeout' => 1,
		'collectionName' => 'Cache',
		'databaseName' => 'database'
)
```

6. 使用files,xcache,apc,cookie驱动

```
$session->setDriver('files', $config);
```

#### 获取SESSION数据

[](#获取session数据)

```
$session->item([$item]);
```

`$item`为要获取的键名，若不存在则返回`NULL`,若不传，则返回所有SESSION数据

#### 设置SESSION数据

[](#设置session数据)

```
$session->set($item, $value);
```

#### 删除SESSION数据

[](#删除session数据)

```
$session->unset($item, $value);
```

#### 清除SESSION数据

[](#清除session数据)

```
$session->destroy();
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~2 days

Total

2

Last Release

2545d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d779dc4497d871757a46a28830e523d6e1709d5bf21bface555522d5f9eba579?d=identicon)[caichuanhai](/maintainers/caichuanhai)

---

Top Contributors

[![caichuanhai](https://avatars.githubusercontent.com/u/5926373?v=4)](https://github.com/caichuanhai "caichuanhai (7 commits)")

### Embed Badge

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

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

PHPackages © 2026

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