Skip to content

Installation

Muhammet Şafak edited this page May 29, 2026 · 1 revision

Installation

Requirements

PHP ^8.1 (tested on 8.1 – 8.4)
Core extensions None
Adapter extensions Depends on the adapter you choose — see below

The package core has zero runtime dependencies. Each adapter only needs its own backend extension, and only when you actually use it.

Install via Composer

composer require initphp/sessions

Classes are autoloaded under the InitPHP\Sessions namespace via PSR-4:

{
    "autoload": {
        "psr-4": {
            "InitPHP\\Sessions\\": "src/"
        }
    }
}

Per-adapter requirements

Install only what the adapter you pick needs:

Adapter Needs
File Nothing extra
Redis ext-redis
PDO ext-pdo + a driver (pdo_mysql, pdo_pgsql, pdo_sqlite, …)
Cookie composer require initphp/encryption + ext-openssl
Memcache / Memcached ext-memcached (preferred) or ext-memcache
MongoDB ext-mongodb

These are declared as suggest entries in composer.json, so Composer reminds you about them but never forces them on.

Verifying the install

<?php
require __DIR__ . '/vendor/autoload.php';

use InitPHP\Sessions\Session;

Session::createImmutable()->start();
Session::set('hello', 'world');

echo Session::get('hello'); // world

If the autoloader cannot find the class, re-run composer dump-autoload and make sure your script requires vendor/autoload.php before using Session.

Supported PHP versions in CI

Every pull request runs the test matrix against:

  • PHP 8.1 (also with lowest dependencies)
  • PHP 8.2
  • PHP 8.3
  • PHP 8.4

Static analysis (PHPStan level 8) and coding-style (PSR-12) checks run on every PR as well. If you hit a regression on a supported version, please file an issue and include the output of php -v.

Next steps

Clone this wiki locally