- Configure your configuration file.
- Create client.php or server.php file
- Call methods
- Run from CLI or extends
settings:
socket_type: tcp
address: 127.0.0.1
port: 8000
content_length: 2048
settings:
socket_type: unix
address: socket.sock
content_length: 2048
<?php
require_once 'vendor/autoload.php';
use Qonsillium\QonsilliumSocket;
use Qonsillium\ServerSocket;
$server = new QonsilliumSocket('config.yaml');
$server->runServer(function(ServerSocket $socket) {
echo $socket->send('Hello from server!');
});
<?php
require_once 'vendor/autoload.php';
use Qonsillium\QonsilliumSocket;
use Qonsillium\ClientSocket;
$server = new QonsilliumSocket('config.yaml');
$server->runClient(function(ClinetSocket $socket) {
echo $socket->send('Hello from client!');
});
john@doe:/workdir/$ php server.php
john@doe:/workdir/$ php client.php
<?php
namespace App;
use Qonsillium\QonsilliumSocket
use Qonillium\ClientSocket
class SocketMessagePrinter extends QonsilliumSocket
{
public function handleServerSocketMessage(string $myMessage)
{
$serverMessage = $this->runClient(function(ClientSocket $client) use ($myMessage) {
return $client->send($myMessage);
});
if ($serverMessage === 'Hello from server!') {
// handle this action
}
}
}
But when you will instantiate handler class don't forget to set configuration file with socket settings in constructor method