php-standard-library/channel
A lightweight PHP standard library component that provides a channel abstraction for passing messages between producers and consumers. Useful for simple concurrency patterns, pipelines, and event-style communication with a minimal, dependency-free API.
Illuminate\Queue). Key fit areas:
OrderService → PaymentService) with channels, reducing latency and coupling.user.created → notify.slack).pcntl/pthreads). Assess compatibility with Laravel’s default runtime (PHP-FPM) vs. async runtimes (Swoole/RoadRunner).$this->app->singleton('channels.notifications', fn() => new BufferedChannel(100));
database queue driver for durability.Mockery to isolate tests:
$channel = Mockery::mock(Channel::class);
$channel->shouldReceive('send')->once();
pcntl_fork).sync queue driver for your workload.memory_get_usage().pcntl/pthreads can introduce race conditions. Validate with:
psalm for type safety).$received = $channel->receive(1.0); // Timeout after 1 second
finally blocks:
try {
$data = $channel->receive();
// Process data
} finally {
$channel->close();
}
pcntl signals) may break in future PHP versions.telescope.OrderService ↔ InventoryService) without HTTP overhead.pcntl for process-based concurrency (enable in php.ini).pthreads for thread safety (optional, but recommended for complex workflows).UserService and NotificationService with a channel:
// Before: HTTP call
$response = Http::post('notification-service/users', ['user_id' => $user->id]);
// After: Channel
$channel = app('channels.notifications');
$channel->send('user.created', $user->id);
[Laravel HTTP Request] → [Channel: Internal Workflow] → [Queue: External Email]
// Channel for internal notification
$channel = app('channels.user-updates');
$channel->send('user.created', $userData);
// Queue for external email
SendWelcomeEmail::dispatch($userData);
user.created → notify).class ProcessUserUpdates implements ShouldQueue
{
public function handle()
{
$channel = app('channels.user-updates');
while (true) {
$data = $channel->receive();
// Process update
}
}
}
Event dispatches for internal consumers:
// Before: Event
event(new UserCreated($user));
// After: Channel
$channel = app('channels.user-events');
$channel->send('user.created', $user);
Illuminate\Bus).ReactPHP) if mixing with channels.Mockery:
$channel = Mockery::mock(BufferedChannel::class);
$channel->shouldReceive('send')->with('data')->once();
Process facade to simulate multi-process consumers:
Process::mustRun(base_path('artisan'), ['channel:consume']);
pcntl, pthreads) and configure php.ini:
disable_functions =
max_children = 20 ; For pcntl
How can I help you explore Laravel packages today?