1
0
mirror of https://github.com/danog/ipc.git synced 2024-12-11 16:59:49 +01:00
ipc/test/Fixtures/server.php
2020-03-05 21:16:53 +01:00

37 lines
861 B
PHP

<?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) {
throw new \RuntimeException('Socket is not instance of ChanneledSocket');
}
$ping = yield $socket->receive();
if ($ping !== 'ping') {
throw new \RuntimeException("Received $ping instead of ping!");
}
yield $socket->send('pong');
yield $socket->disconnect();
$server->close();
return $server->accept();
};