PHP code example of qxsch / multi-process-server
1. Go to this page and download the library: Download qxsch/multi-process-server library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
qxsch / multi-process-server example snippets
$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 = new \QXS\MultiProcessServer\TCPClient(12345); // connect to 127.0.0.1 on port 12345
$client->send("hi");
echo $client->receive() ."\n";