qxsch / multi-process-server
Runs a multi threaded server.
v1.0.1
2017-03-23 00:39 UTC
Requires
- php: >=5.3.2
- ext-pcntl: *
- ext-posix: *
- ext-sockets: *
Requires (Dev)
- phpunit/phpunit: >=4.0.0
Suggests
- php: >=5.5.0
This package is not auto-updated.
Last update: 2024-11-17 20:53:11 UTC
README
A multithreaded server for PHP
The TCPServer class provides a very simple interface to communicate with a client. You can control how many processes should be allowed to run concurrently. The TCPServer can be fully observed.
The TCPClient class provides a very simple interface to communicate with a server.
You can send any data between the client and the server that can be serialized.
TLS Encryption with server and client certificate is supported (mutual authentication).
A simple example
Server Code:
<?php $server = new \QXS\MultiProcessServer\TCPServer(12345); // setup the server for 127.0.0.1 on port 12345 // UNCOMMENT THE NEXT LINE TO ADD IMPERSONATION //$server->runAsUser("nobody"); $server->attach(new \QXS\MultiProcessServer\Observers\EchoObserver()); $server->create(new \QXS\MultiProcessServer\ClosureServerWorker( /** * @param \QXS\MultiProcessServer\SimpleSocket $serverSocket the socket to communicate with the client */ function(\QXS\MultiProcessServer\SimpleSocket $serverSocket) { // receive data and send it back $data=$serverSocket->receive(); echo "$data\n"; $serverSocket->send($data); } ));
Client Code:
<?php $client = new \QXS\MultiProcessServer\TCPClient(12345); // connect to 127.0.0.1 on port 12345 $client->send("hi"); echo $client->receive() ."\n";