Skip to content

vrza/php-symplib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synchronous Message Passing framework for PHP

User-friendly, object-oriented API for message passing between PHP processes.

Stream sockets are used as message passing channels. A single server can listen for and handle messages on multiple channels, which can include any mix of Unix domain sockets and TCP/IP (v4 and v6).

Protocol

Messages use a simple wire protocol, where the first 8 bytes of the message specify the length of the rest of the message (unsigned, big endian).

The payload of the message is provided by the user. Serialization format etc. is left to user’s choice.

Getting started

See full working examples in the test/ directory.

Simple server

class MyMessageHandler implements MessageHandler {
    public function handleMessage(string $msg): string {
        return "Hello, client, I received: $msg";
    }
}

$handler = new MyMessageHandler();
$address = new InetSocketAddress('127.0.0.1', 1389, AF_INET);
$server = new SocketStreamsServer([
    new SocketData($address, $handler)
]);

$server->listen();
while (true)
    $server->checkMessages(1);

Simple client

$address = new InetSocketAddress('127.0.0.1', 1389);
$client = new SocketStreamClient($address);

$client->connect();
$client->sendMessage("Hello, server!");
$response = $client->receiveMessage();
echo $response . PHP_EOL;
$client->disconnect();

About

Synchronous Message Passing Framework for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages