cursedcoder/emessenger

通过协议发送消息到PHP进程。

0.1 2016-04-13 05:06 UTC

This package is not auto-updated.

Last update: 2024-09-26 00:24:45 UTC


README

发送任何消息到远程进程。

可用的传输方式

  • Unix套接字文件(unix://tmp/log.sock)
  • 后续更多:tcp, udp等。

示例

<?php

// logserver.php

use React\EventLoop\Factory as EventLoopFactory;
use EMessenger\Transport\UnixTransport;
use EMessenger\MessengerFactory;

$loop = EventLoopFactory::create();

$transport = new UnixTransport($loop, 'unix://tmp/log.sock');
$messenger = MessengerFactory::server($transport);

$messenger->send('debug', 'This is a test message.');
<?php

// logwriter.php

use React\EventLoop\Factory as EventLoopFactory;
use EMessenger\Transport\UnixTransport;
use EMessenger\MessengerFactory;

$loop = EventLoopFactory::create();

$transport = new UnixTransport($loop, 'unix://tmp/log.sock');
$messenger = MessengerFactory::client($transport);

$messenger->on('debug', function($debug) {
    echo 'Received debug message: ' . $debug;
});