azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The Channel component provides message-passing channels for async communication, inspired by Go's channels and Rust's std::sync::mpsc. A channel splits into a SenderInterface and a ReceiverInterface, giving you a clear separation between the producing and consuming sides.
Channels come in two flavors:
Both factory functions return a [ReceiverInterface, SenderInterface] pair:
@example('async/channel-basic.php')
@example('async/channel-send-receive.php')
send() waits for space if the channel is full. receive() waits for a message if the channel is empty. For non-blocking alternatives, use trySend() and tryReceive(), which throw immediately instead of waiting:
@example('async/channel-try-send-receive.php')
Closing a channel signals that no more messages will be sent. Messages already in the channel can still be received:
@example('async/channel-closing.php')
@example('async/channel-inspecting.php')
For unbounded channels, getCapacity() returns null and isFull() always returns false.
@example('async/channel-producer-consumer.php')
Distribute work across several consumers by sharing the receiver:
@example('async/channel-fan-out.php')
Both send() and receive() accept an optional CancellationTokenInterface. This is useful when you don't want to wait indefinitely for a message or for space in a bounded channel:
@example('async/channel-cancellation.php')
trySend() and tryReceive() are non-blocking and don't need cancellation tokens -- they throw immediately if the channel is full or empty.
See src/Psl/Channel/ for the full API.
How can I help you explore Laravel packages today?