PHPackages                             hoa/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. hoa/session

AbandonedArchivedLibrary

hoa/session
===========

The Hoa\\Session library.

0.17.01.16(9y ago)93.0k7[1 issues](https://github.com/hoaproject/Session/issues)1BSD-3-ClausePHP

Since Sep 16Pushed 9y ago8 watchersCompare

[ Source](https://github.com/hoaproject/Session)[ Packagist](https://packagist.org/packages/hoa/session)[ Docs](https://hoa-project.net/)[ RSS](/packages/hoa-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (12)Used By (1)

 [![Hoa](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)](https://camo.githubusercontent.com/2b5c32c5d4bc5e9298821b22d364a522e2dbc0295c1c011b1f9f86a4d07df07e/68747470733a2f2f7374617469632e686f612d70726f6a6563742e6e65742f496d6167652f486f612e737667)

---

 [![Build status](https://camo.githubusercontent.com/fb704864306bb23ad0cbb9be7a047fd695e4c3c6711a60d536fdfc892f3cb0b4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f686f6170726f6a6563742f73657373696f6e2f6d61737465722e737667)](https://travis-ci.org/hoaproject/session) [![Code coverage](https://camo.githubusercontent.com/bd9d65ba716a0c6ffe8683aa1f620287a4896490807e289e56aaf3601721b628/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f686f6170726f6a6563742f73657373696f6e2f6d61737465722e737667)](https://coveralls.io/github/hoaproject/session?branch=master) [![Packagist](https://camo.githubusercontent.com/60e8d261967c0d2caf5ebde4072fb6193b56f1761d0852cf201fb9e1e67a9711/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f686f612f73657373696f6e2e737667)](https://packagist.org/packages/hoa/session) [![License](https://camo.githubusercontent.com/e8202d9150d4bd074fb67a6699989108477c8e2a71f88b76dab60419ec61bef8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f686f612f73657373696f6e2e737667)](https://hoa-project.net/LICENSE)

 Hoa is a **modular**, **extensible** and **structured** set of PHP libraries.
 Moreover, Hoa aims at being a bridge between industrial and research worlds.

Hoa\\Session
============

[](#hoasession)

[![Help on IRC](https://camo.githubusercontent.com/4dbc9c9d28c30cf1ab591f4bb8212fe4dbddc734145df532a9bb86b09878d4c6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d253233686f6170726f6a6563742d6666303036362e737667)](https://webchat.freenode.net/?channels=#hoaproject)[![Help on Gitter](https://camo.githubusercontent.com/8c4c85951788ff606b1268cb3dd946be05e3054795455d0a7b9250711bc2ac05/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f68656c702d6769747465722d6666303036362e737667)](https://gitter.im/hoaproject/central)[![Documentation](https://camo.githubusercontent.com/7059ad5f1a363f9098686c59d432f01d7330aed9d4b6c8111d985fd64cfc6c60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646f63756d656e746174696f6e2d6861636b5f626f6f6b2d6666303036362e737667)](https://central.hoa-project.net/Documentation/Library/Session)[![Board](https://camo.githubusercontent.com/fd81654ba14b3aca3a713e1b471bc3fc3ba7b5bb3761ccffd6eea2e2ed1fa5ca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6f7267616e69736174696f6e2d626f6172642d6666303036362e737667)](https://waffle.io/hoaproject/session)

This library allows to manipulate sessions easily by creating “namespaces”, i.e. an entry in the `$_SESSION` global variable. It also allows to manipulate flash sessions.

Each namespace has a profile. Amongst many things, it implies we can control lifetime of each namespace individually. This library can be used in conjunction of `ext/session` (especially to configure session).

[Learn more](https://central.hoa-project.net/Documentation/Library/Session).

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/), to include this library into your dependencies, you need to require [`hoa/session`](https://packagist.org/packages/hoa/session):

```
$ composer require hoa/session '~0.0'
```

For more installation procedures, please read [the Source page](https://hoa-project.net/Source.html).

Testing
-------

[](#testing)

Before running the test suites, the development dependencies must be installed:

```
$ composer install
```

Then, to run all the test suites:

```
$ vendor/bin/hoa test:run
```

For more information, please read the [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html).

Quick usage
-----------

[](#quick-usage)

We propose a quick overview of three usages: manipulating a namespace, expiration handling and destructing a namespace.

### Manipulating a namespace

[](#manipulating-a-namespace)

We will start a `user` namespace. If this namespace is empty, it implies two things: either the session is newly created or it has expired. In all cases, we print `first time` and save the current time in `foo`. And if the namespace is not empty, we print `other times` and dump the saved time. Thus:

```
$user = new Hoa\Session\Session('user');

if ($user->isEmpty()) {
    echo 'first time', "\n";
    $user['foo'] = time();
} else {
    echo 'other times', "\n";
    var_dump($user['foo']);
}
```

First execution will print `first time` and next ones will print `other times`followed by a timestamp.

No need to start the session, it will be done automatically. But if we want to, we can use the `session_start` function or the `Hoa\Session\Session::start`static method, which is more sophisticated.

### Expiration handling

[](#expiration-handling)

If a namespace expires before the session, either an event is fired on the channel `hoa://Event/Session/:expired` or an exception `Hoa\Session\Exception\Expired` is thrown (if no callable listens the channel). We can test if the namespace is expired with the help of the `Hoa\Session\Session::isExpired` method or we can declare the namespace as expired with the help of the `Hoa\Session\Session::hasExpired` method (this method will throw an exception or fire an event).

Considering the previous example, we will declare the namespace as expired when the session is empty:

```
Hoa\Event\Event::getEvent('hoa://Event/Session/user:expired')
    ->attach(function (Hoa\Event\Bucket $bucket) {
        echo 'expired', "\n";
    });

$user = new Hoa\Session\Session('user');

if ($user->isEmpty()) {
    $user->hasExpired();
    echo 'first time', "\n";
    $user['foo'] = time();
} else {
    echo 'other times', "\n";
    var_dump($user['foo']);
}
```

First execution will print `expired` and `first time`, and next ones will print `other times` followed by a timestamp.

If an empty session does not imply an expiration (depending of our workflow and configuration), we could avoid the call to `$user->hasExpired()`: the test is automatically done during the construction of the namespace.

We can modify the lifetime by using the `Hoa\Session\Session::rememberMe`method; for example:

```
$user->rememberMe('+1 day');
```

And we can also forget the namespace:

```
$user->forgetMe();
```

### Destructing a namespace

[](#destructing-a-namespace)

Destructing a namespace uses the `Hoa\Session\Session::delete` method:

```
$user = new Hoa\Session\Session('user');
$user['foo'] = 'bar';
$user->delete();
```

Stored data in the namespace are **lost** because we explicitly delete the namespace.

If we want to destroy the session (including all namespaces and cookie), we could use the `Hoa\Session\Session::destroy` static method. Again, no need to previously start the session manually if it is not done.

Documentation
-------------

[](#documentation)

The [hack book of `Hoa\Session`](https://central.hoa-project.net/Documentation/Library/Session)contains detailed information about how to use this library and how it works.

To generate the documentation locally, execute the following commands:

```
$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open
```

More documentation can be found on the project's website: [hoa-project.net](https://hoa-project.net/).

Getting help
------------

[](#getting-help)

There are mainly two ways to get help:

- On the [`#hoaproject`](https://webchat.freenode.net/?channels=#hoaproject)IRC channel,
- On the forum at [users.hoa-project.net](https://users.hoa-project.net).

Contribution
------------

[](#contribution)

Do you want to contribute? Thanks! A detailed [contributor guide](https://hoa-project.net/Literature/Contributor/Guide.html) explains everything you need to know.

License
-------

[](#license)

Hoa is under the New BSD License (BSD-3-Clause). Please, see [`LICENSE`](https://hoa-project.net/LICENSE) for details.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 95.9% 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 ~85 days

Recently: every ~172 days

Total

11

Last Release

3406d ago

### Community

Maintainers

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

---

Top Contributors

[![Hywan](https://avatars.githubusercontent.com/u/946104?v=4)](https://github.com/Hywan "Hywan (70 commits)")[![shulard](https://avatars.githubusercontent.com/u/482993?v=4)](https://github.com/shulard "shulard (1 commits)")[![stephpy](https://avatars.githubusercontent.com/u/232744?v=4)](https://github.com/stephpy "stephpy (1 commits)")[![vonglasow](https://avatars.githubusercontent.com/u/1275202?v=4)](https://github.com/vonglasow "vonglasow (1 commits)")

---

Tags

hoalibraryphpsessiondatalibraryhandlersessionnamespacepersistent

### Embed Badge

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

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

PHPackages © 2026

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