1
0
mirror of https://github.com/danog/ipc.git synced 2024-11-26 20:15:05 +01:00
Go to file
2021-05-03 15:39:45 +02:00
examples Add missing files 2020-07-17 14:37:37 +02:00
lib cs-fix 2021-05-03 15:39:45 +02:00
test cs-fix 2021-05-03 15:39:45 +02:00
.gitignore Better error handling and fallbacks 2021-04-21 15:27:22 +02:00
.php_cs.dist First commit 2020-02-14 20:31:11 +01:00
.travis.yml cs-fix 2020-03-05 21:16:53 +01:00
appveyor.yml First commit 2020-02-14 20:31:11 +01:00
composer.json Use less specific version constraints 2020-03-06 14:15:43 +01:00
CONTRIBUTING.md First commit 2020-02-14 20:31:11 +01:00
LICENSE First commit 2020-02-14 20:31:11 +01:00
phpunit.xml.dist Better error handling and fallbacks 2021-04-21 15:27:22 +02:00
README.md Trigger build 2021-01-30 20:51:30 +01:00

IPC

Build Status Build status License

danog/ipc provides an async IPC server.

Installation

composer require danog/ipc

Example

Server:

<?php

require 'vendor/autoload.php';

use Amp\Ipc\Sync\ChannelledSocket;
use Amp\Loop;

use function Amp\asyncCall;
use function Amp\Ipc\listen;

Loop::run(static function () {
    $clientHandler = function (ChannelledSocket $socket) {
        echo "Accepted connection".PHP_EOL;

        while ($payload = yield $socket->receive()) {
            echo "Received $payload".PHP_EOL;
            if ($payload === 'ping') {
                yield $socket->send('pong');
                yield $socket->disconnect();
            }
        }
        echo "Closed connection".PHP_EOL."==========".PHP_EOL;
    };

    $server = listen(\sys_get_temp_dir().'/test');
    while ($socket = yield $server->accept()) {
        asyncCall($clientHandler, $socket);
    }
});

Client:

<?php

require 'vendor/autoload.php';

use Amp\Ipc\Sync\ChannelledSocket;
use Amp\Loop;

use function Amp\asyncCall;
use function Amp\Ipc\connect;

Loop::run(static function () {
    $clientHandler = function (ChannelledSocket $socket) {
        echo "Created connection.".PHP_EOL;

        while ($payload = yield $socket->receive()) {
            echo "Received $payload".PHP_EOL;
        }
        echo "Closed connection".PHP_EOL;
    };

    $channel = yield connect(\sys_get_temp_dir().'/test');
    asyncCall($clientHandler, $channel);
    yield $channel->send('ping');
});