1
0
mirror of https://github.com/danog/ipc.git synced 2024-12-02 17:37:48 +01:00
ipc/test/Fixtures/echoServer.php

31 lines
721 B
PHP
Raw Normal View History

2020-07-17 14:37:37 +02:00
<?php
\error_reporting(E_ALL);
\ini_set('log_errors', 1);
\ini_set('error_log', '/tmp/amphp.log');
\error_log('Inited IPC test!');
use Amp\Ipc\IpcServer;
use Amp\Ipc\Sync\ChannelledSocket;
use Amp\Parallel\Sync\Channel;
use function Amp\delay;
return function (Channel $channel) use ($argv) {
$server = new IpcServer($argv[1], $argv[2] === "1" ? true : false);
yield $channel->send($server->getUri());
$socket = yield $server->accept();
if (!$socket instanceof ChannelledSocket) {
2020-09-25 16:50:16 +02:00
throw new \RuntimeException('Socket is not instance of ChannelledSocket');
2020-07-17 14:37:37 +02:00
}
while (yield $socket->receive());
yield $socket->disconnect();
$server->close();
return $server->accept();
};