danog / ipc
IPC component for Amp.
1.1.0
2026-10-18 18:06 UTC
Requires
- php: >=8.1
- amphp/byte-stream: ^2.1.2
- amphp/parallel: ^2.3.1
- amphp/parser: ^1.1.1
Requires (Dev)
- amphp/amp: v3.x-dev
- amphp/php-cs-fixer-config: v2.x-dev
- amphp/phpunit-util: v3.x-dev
- phpunit/phpunit: ^9.6.22
- psalm/phar: ^5.26.1
Suggests
- ext-sockets: Required for UNIX socket support on Windows (TCP is used otherwise)
Provides
None
Conflicts
None
Replaces
None
README
danog/ipc provides an async IPC server.
Installation
composer require danog/ipc
Transports
IpcServer picks the first transport that works (or the ones selected with the TYPE_* flags):
- UNIX sockets: on Windows (10 1803+) these require
ext-sockets, since PHP streams don't supportAF_UNIXthere; - FIFOs (Linux only);
- TCP on
127.0.0.1, as a last resort: any local user can connect to it.
connect() takes the same URI as the server, whatever the transport: on Windows, and with TCP, the URI is a file
holding the endpoint.
Example
Server:
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Amp\Ipc\Sync\ChannelledSocket; use function Amp\async; use function Amp\Ipc\listen; $clientHandler = function (ChannelledSocket $socket) { echo "Accepted connection".PHP_EOL; while ($payload = $socket->receive()) { echo "Received $payload".PHP_EOL; if ($payload === 'ping') { $socket->send('pong'); $socket->disconnect(); } } echo "Closed connection".PHP_EOL."==========".PHP_EOL; }; $server = listen(sys_get_temp_dir().'/test'); while ($socket = $server->accept()) { async($clientHandler, $socket); }
Client:
<?php declare(strict_types=1); require 'vendor/autoload.php'; use Amp\Ipc\Sync\ChannelledSocket; use function Amp\async; use function Amp\Ipc\connect; $clientHandler = function (ChannelledSocket $socket) { echo "Created connection.".PHP_EOL; while ($payload = $socket->receive()) { echo "Received $payload".PHP_EOL; } echo "Closed connection".PHP_EOL; }; $channel = connect(sys_get_temp_dir().'/test'); $thread = async($clientHandler, $channel); $channel->send('ping'); $thread->await();