{"id":15524890,"url":"https://github.com/ericmann/sessionz","last_synced_at":"2026-04-14T21:01:54.905Z","repository":{"id":48518132,"uuid":"74243976","full_name":"ericmann/sessionz","owner":"ericmann","description":"PHP library for smarter session management in modular applications","archived":false,"fork":false,"pushed_at":"2022-10-20T08:00:57.000Z","size":38,"stargazers_count":57,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-20T06:40:38.377Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericmann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-20T00:30:02.000Z","updated_at":"2024-08-28T17:45:02.000Z","dependencies_parsed_at":"2022-09-02T01:21:40.619Z","dependency_job_id":null,"html_url":"https://github.com/ericmann/sessionz","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ericmann/sessionz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fsessionz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fsessionz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fsessionz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fsessionz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericmann","download_url":"https://codeload.github.com/ericmann/sessionz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericmann%2Fsessionz/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31815080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T18:05:02.291Z","status":"ssl_error","status_checked_at":"2026-04-14T18:05:01.765Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T10:53:30.822Z","updated_at":"2026-04-14T21:01:54.900Z","avatar_url":"https://github.com/ericmann.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Sessionz [![CI](https://github.com/ericmann/sessionz/actions/workflows/ci.yml/badge.svg)](https://github.com/ericmann/sessionz/actions/workflows/ci.yml) [![Latest Stable Version](https://img.shields.io/packagist/v/ericmann/sessionz.svg)](https://packagist.org/packages/ericmann/sessionz) [![License](https://img.shields.io/packagist/l/ericmann/sessionz.svg)](https://packagist.org/packages/ericmann/sessionz)\n\nSessionz is a PHP library for smarter session management in modular applications.\n\n## Requirements\n\n- PHP 7.4 or newer (tested against 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5)\n- [Composer](https://getcomposer.org/)\n\n## Installation\n\n```bash\ncomposer require ericmann/sessionz\n```\n\n## Quick Start\n\nAfter loading your autoloader, initialize the core session manager and register the handlers you need:\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n\nEAMann\\Sessionz\\Manager::initialize()\n    -\u003eaddHandler( new \\EAMann\\Sessionz\\Handlers\\DefaultHandler() )\n    -\u003eaddHandler( new \\EAMann\\Sessionz\\Handlers\\EncryptionHandler( getenv('session_passkey') ) )\n    -\u003eaddHandler( new \\EAMann\\Sessionz\\Handlers\\MemoryHandler() );\n\nsession_start();\n```\n\nThe above example adds, in order:\n\n- The default PHP session handler (which uses files for storage)\n- An encryption middleware such that session data will be encrypted at rest on disk\n- An in-memory cache to avoid round-trips to the filesystem on read\n\n## How Handlers Work\n\nThe session manager maintains a list of registered \"handlers\" to which it passes requests from the PHP engine to:\n\n- Read a session\n- Write a session\n- Create a session store\n- Clean up (garbage collect) expired sessions\n- Delete a session\n\nEach handler must implement the `Handler` interface so the session manager knows how to work with them.\n\n### Middleware Structure\n\nThe overall structure of the handler stack is identical to that of a middleware stack in a modern PHP application. You can read more about the general philosophy [on Slim's website](https://www.slimframework.com/docs/v4/concepts/middleware.html).\n\nIn general, stack operations will flow from the outside-in, starting by invoking the appropriate operation on the most recently registered handler and walking down the stack to the oldest handler. Each handler has the option to halt execution and return data immediately, or can invoke the passed `$next` callback to continue operation.\n\nUsing the quick start example above:\n\n- Requests start in the `MemoryHandler`\n- If necessary, they then pass to the `EncryptionHandler`\n- Requests always pass from encryption to the `DefaultHandler`\n- If necessary, they then pass to the (hidden) `BaseHandler`\n- Then everything returns because the base handler doesn't pass anything on\n\n## Available Handlers\n\n### `DefaultHandler`\n\nThe default session handler merely exposes PHP's default session implementation to our custom manager. Including this handler will provide otherwise standard PHP session functionality to the project as a whole, but this functionality can be extended by placing other stacks on top.\n\n### `EncryptionHandler`\n\nSessions stored on disk (the default implementation) or in a separate storage system (Memcache, MySQL, or similar) should be encrypted _at rest_. This handler will automatically encrypt any information passing through it on write and decrypt data on read. It does not store data on its own.\n\nThis handler requires a symmetric encryption key when it's instantiated. This key should be an ASCII-safe string generated by [Defuse PHP Encryption](https://github.com/defuse/php-encryption) (a dependency of this library):\n\n```php\nuse Defuse\\Crypto\\Key;\n\n$rawKey = Key::createNewRandomKey();\n$key    = $rawKey-\u003esaveToAsciiSafeString();\n\n// Store $key somewhere safe (e.g. an environment variable) and pass it\n// back into the EncryptionHandler constructor on every request.\n```\n\n### `MemoryHandler`\n\nIf the final storage system presented to the session manager is remote, reads and writes can take a non-trivial amount of time. Storing session data in memory helps to make the application more performant. Reads will stop at this layer in the stack if the session is found (i.e. the cache is hot) but will flow to the next layer if no session exists. When a session is found in a subsequent layer, this handler will update its cache to make the data available upon the next lookup.\n\nWrites will update the cache and pass through to the next layer in the stack.\n\n### Abstract handlers\n\nThe `BaseHandler` class is always instantiated and included at the root of the handler stack by default. This is so that, no matter what handlers you add in to the stack, the session manager will always return a standard, reliable set of information.\n\nThe `NoopHandler` class is provided for you to build additional middleware atop a standard interface that \"passes through\" to the next layer in the stack by default. The `EncryptionHandler`, for example, inherits from this class as it doesn't store or read data, but merely manipulates information before passing it along. Another implementation might be a logging interface to track when sessions are accessed/updated.\n\n## Development\n\nClone the repository and install dev dependencies:\n\n```bash\ngit clone https://github.com/ericmann/sessionz.git\ncd sessionz\ncomposer install\n```\n\nRun the test suite:\n\n```bash\ncomposer test\n```\n\nStatic analysis is provided by [PHPStan](https://phpstan.org/) and runs automatically in CI.\n\n## Contributing\n\nIssues and pull requests are welcome at \u003chttps://github.com/ericmann/sessionz\u003e. Please ensure new code is covered by tests and that `composer test` passes across the supported PHP matrix before opening a PR.\n\n## License\n\n[MIT](LICENSE.md)\n\n## Credits\n\nThe middleware implementation is inspired heavily by the request middleware stack presented by [the Slim Framework](https://www.slimframework.com/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmann%2Fsessionz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericmann%2Fsessionz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericmann%2Fsessionz/lists"}