2
votes

The server script would run continuously.

Other scripts are normal websites, that should be able to communicate with the server script.

I've come across Ratchet (https://github.com/cboden/Ratchet), tried the example from here: http://socketo.me/docs/hello-world and it works :D

But the client needs javascript. And I would like to send the request to the server with PHP because the messages are linux commands, and I wouldn't want site visitors to be able to send linux commands to my server script. Also, only messages from scripts from "localhost" should be taken into consideration.

Is it possible to do this with Ratchet? Or are there other solutions for this?

2

2 Answers

2
votes

Ratchet doesn't offer a client. I would look at phpwebsocket for your php websocket client.

To ensure that client connections come from localhost in Ratchet, change this bit of code from the Push Integration tutorial:

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
// Binding to 0.0.0.0 means remotes can connect
//$webSock->listen(8080, '0.0.0.0');
// Binding to 127.0.0.1 means the only client that can connect is itself
$webSock->listen(8080, '127.0.0.1');
$webServer = new Ratchet\Server\IoServer(
    new Ratchet\WebSocket\WsServer(
        new Ratchet\Wamp\WampServer(
            $pusher
        )
    ),
    $webSock
);
1
votes

You need to create a proxy PHP script which will handle javascript requests and convert it into CLI commands to your ratchet script.