https://github.com/azjezz/psl
๐ PHP Standard Library - a modern, consistent, centralized, well-typed, non-blocking set of APIs for PHP programmers
https://github.com/azjezz/psl
ansi async collection data-structures encoding grapheme-cluster html io json math multibyte-strings non-blocking password-hashing php pseudo-random secure-random shell standard-library terminal-ui type-assertion
Last synced: 9 days ago
JSON representation
๐ PHP Standard Library - a modern, consistent, centralized, well-typed, non-blocking set of APIs for PHP programmers
- Host: GitHub
- URL: https://github.com/azjezz/psl
- Owner: azjezz
- License: mit
- Created: 2019-12-24T01:19:10.000Z (about 6 years ago)
- Default Branch: next
- Last Pushed: 2026-03-08T20:32:37.000Z (11 days ago)
- Last Synced: 2026-03-09T00:57:39.398Z (11 days ago)
- Topics: ansi, async, collection, data-structures, encoding, grapheme-cluster, html, io, json, math, multibyte-strings, non-blocking, password-hashing, php, pseudo-random, secure-random, shell, standard-library, terminal-ui, type-assertion
- Language: PHP
- Homepage: https://psl.carthage.software/
- Size: 4.26 MB
- Stars: 1,432
- Watchers: 22
- Forks: 84
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# PSL - PHP Standard Library



[](https://bestpractices.coreinfrastructure.org/projects/4228)
[](https://coveralls.io/github/azjezz/psl)
[](https://dashboard.stryker-mutator.io/reports/github.com/azjezz/psl/next)
[](https://packagist.org/packages/azjezz/psl)
[](https://packagist.org/packages/azjezz/psl)
[](https://packagist.org/packages/azjezz/psl)
A standard library for PHP, inspired by [hhvm/hsl](https://github.com/hhvm/hsl). PSL provides a consistent, centralized, well-typed set of APIs covering async, collections, networking, I/O, cryptography, terminal UI, and more - replacing PHP functions and primitives with safer, async-ready alternatives that error predictably.
**[Documentation](https://psl.carthage.software)** ยท **[Sponsor](https://github.com/sponsors/azjezz)**
## Installation
```shell
composer require azjezz/psl
```
Requires PHP 8.4+.
## Quick Look
### Type-safe data validation
Validate and coerce untrusted data with composable type combinators - shapes, unions, optionals - all with zero reflection overhead.
```php
use Psl\Type;
$userType = Type\shape([
'name' => Type\non_empty_string(),
'age' => Type\positive_int(),
'tags' => Type\vec(Type\string()),
]);
$user = $userType->coerce($untrustedInput);
// array{name: non-empty-string, age: positive-int, tags: list}
```
### Structured concurrency
Run concurrent operations with a single function call. Structured concurrency built on fibers - no promises, no callbacks.
```php
use Psl\Async;
use Psl\TCP;
use Psl\IO;
Async\main(static function(): int {
[$a, $b] = Async\concurrently([
static fn() => TCP\connect('api.example.com', 443),
static fn() => TCP\connect('db.example.com', 5432),
]);
IO\write_error_line('Both connections ready');
return 0;
});
```
### Functional collections
Map, filter, sort, and reshape arrays with pure functions. Separate return types for lists and dicts - no more array key confusion.
```php
use Psl\Vec;
use Psl\Dict;
use Psl\Str;
$names = ['alice', 'bob', 'charlie'];
Vec\map($names, Str\uppercase(...));
// ['ALICE', 'BOB', 'CHARLIE']
Vec\filter($names, fn($n) => Str\length($n) > 3);
// ['alice', 'charlie']
Dict\pull($names, Str\uppercase(...), fn($n) => $n);
// {alice: 'ALICE', bob: 'BOB', charlie: 'CHARLIE'}
```
### TCP server in 10 lines
Production-ready networking primitives. TCP, TLS, UDP, Unix sockets - all async, all composable.
```php
use Psl\Async;
use Psl\TCP;
use Psl\IO;
Async\main(static function(): int {
$server = TCP\listen('127.0.0.1', 8080);
IO\write_error_line('Listening on :8080');
while (true) {
$conn = $server->accept();
Async\run(static function() use ($conn) {
$conn->writeAll("Hello!\n");
$conn->close();
})->ignore();
}
});
```
## Tooling
| Tool | Description |
|---|---|
| [Mago](https://mago.carthage.software/tools/analyzer/configuration-reference#available-plugins) | Enhanced type inference for Mago |
| [Psalm Plugin](https://github.com/php-standard-library/psalm-plugin) | Enhanced type inference for Psalm |
| [PHPStan Extension](https://github.com/php-standard-library/phpstan-extension) | Enhanced type inference for PHPStan |
## Contributing
See [CONTRIBUTING.md](./CONTRIBUTING.md).
## License
MIT - see [LICENSE](./LICENSE).