PHPackages                             anullvalue/phpsessiondbpg - 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. [Database &amp; ORM](/categories/database)
4. /
5. anullvalue/phpsessiondbpg

ActiveLibrary[Database &amp; ORM](/categories/database)

anullvalue/phpsessiondbpg
=========================

PHP8.2+ Session Handler using PostgreSQL

v0.06(2y ago)1582MITPHPPHP &gt;=8.2.0CI passing

Since Jan 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aNullValue/phpsessiondbpg)[ Packagist](https://packagist.org/packages/anullvalue/phpsessiondbpg)[ RSS](/packages/anullvalue-phpsessiondbpg/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (4)Used By (0)

PHP8.2+ Session Handler using PostgreSQL
========================================

[](#php82-session-handler-using-postgresql)

> Many solutions/projects will not require the use of database-backed PHP session handling. In event yours does, and your project requires PostgreSQL 9.5+ anyway, I wrote this solution for you.

Requirements
------------

[](#requirements)

- PostgreSQL 9.5+ (must support "ON CONFLICT DO UPDATE")
- PHP 8.2+
- PostgreSQL connection (via pg\_connect, not PDO)
- Create "session\_data" table as follows (table name (but not schema) may vary; this is just an example):

    ```
      CREATE TABLE public.session_data
      (
          id character varying NOT NULL,
          data character varying NOT NULL,
          touch_epoch integer NOT NULL,
          PRIMARY KEY (id)
      )
      WITH (
          OIDS = FALSE
      )
      TABLESPACE pg_default;

      ALTER TABLE public.session_data
          OWNER to postgres;

      CREATE INDEX session_data__id ON session_data(id);
      CREATE INDEX session_data__touch_epoch ON session_data(touch_epoch);

    ```

Example code
------------

[](#example-code)

```
$dbconn = pg_connect("your connection string here");
require_once 'PHPSessionDbPg.php'; // required only if you are not autoloading this library
$sessions_handler = new \aNullValue\PHPSessionDbPg\PHPSessionDbPg($dbconn,'session_data', 86400);
session_set_save_handler($sessions_handler, true);
session_name('MySessionName'); //optional
session_start();

$_SESSION['something'] = 'foo';
$_SESSION['something_else'] = 'bar';
echo session_id(),'',$_SESSION['something'],'',$_SESSION['something_else'] ;

```

Misc
----

[](#misc)

```
Inspired by https://github.com/iKevinShah/PGSessions

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~933 days

Total

3

Last Release

801d ago

PHP version history (2 changes)v0.03PHP &gt;=7.0.0

v0.06PHP &gt;=8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7889ea8a117da7610a774b81367e2679fd15f4aa17f70895c8d49cc9a88a5ecd?d=identicon)[aNullValue](/maintainers/aNullValue)

---

Top Contributors

[![aNullValue](https://avatars.githubusercontent.com/u/3424516?v=4)](https://github.com/aNullValue "aNullValue (12 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")[![nbsoftware](https://avatars.githubusercontent.com/u/1502008?v=4)](https://github.com/nbsoftware "nbsoftware (1 commits)")

---

Tags

phpphp-librarypostgresqlsessionssessionstorage

### Embed Badge

![Health badge](/badges/anullvalue-phpsessiondbpg/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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