1
0
mirror of https://github.com/danog/ipc.git synced 2024-11-26 20:15:05 +01:00
ipc/examples/client.php
2020-02-14 20:31:11 +01:00

25 lines
609 B
PHP

<?php
require 'vendor/autoload.php';
use Amp\Loop;
use Amp\Ipc\Sync\ChannelledSocket;
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;
$socket->close();
}
echo "Closed connection".PHP_EOL;
};
$channel = yield connect(sys_get_temp_dir().'/test');
asyncCall($clientHandler, $channel);
yield $channel->send('ping');
});