承接 innmind/ipc 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

innmind/ipc

Composer 安装命令:

composer require innmind/ipc

包简介

Inter-process communication

README 文档

README

CI codecov Type Coverage

Library to abstract the communication between processes by using message passing over unix sockets.

Installation

composer require innmind/ipc

Usage

# Process A
use Innmind\IPC\{
    IPC,
    Process\Name,
    Continuation,
    Server,
    Message,
};
use Innmind\OperatingSystem\Factory;
use Innmind\Immutable\Monoid;

/**
 * @psalm-immutable
 * @implements Monoid<int>
 */
final class Addition implements Monoid
{
    public function identity(): int
    {
        return 0;
    }

    public function combine(mixed $a, mixed $b): int
    {
        return $a + $b;
    }
}

$ipc = IPC::build(Factory::build());
$counter = $ipc
    ->serve(Name::of('a'))
    ->sink(new Addition)
    ->monitor(static fn(int $counter, Server\Continuation $continuation) => match ($counter) {
        42 => $continuation->finish(),
        default => $continuation,
    })
    ->with(
        static fn(Message $message, Continuation $continuation, int $counter) => $continuation
            ->respond($message)
            ->carryWith($counter + 1),
    )
    ->unwrap();
// $counter will always be 42 in this case
# Process B
use Innmind\IPC\{
    IPC,
    Process,
    Process\Name,
    Message,
};
use Innmind\OperatingSystem\Factory;
use Innmind\MediaType\{
    MediaType,
    TopLevel,
};
use Innmind\Immutable\{
    Str,
    Sequence,
};

$ipc = IPC::build(Factory::build());
$server = Name::of('a');
$response = $ipc
    ->connectTo($server)
    ->flatMap(
        static fn(Process $process) => $process
            ->send(Sequence::of(
                Message::of(
                    MediaType::from(TopLevel::text, 'plain'),
                    Str::of('hello world'),
                ),
            ))
            ->map(static fn() => $process),
    )
    ->flatMap(fn(Process $process) => $process->wait())
    ->match(
        static fn(Message $message) => 'server responded '.$message->content()->toString(),
        static fn() => 'no response from the server',
    );
print($message);

The above example will result in the output server responded hello world in the process B.

You can run the process B 42 times before the server in the process A stops.

统计信息

  • 总下载量: 2.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固