如何制作“;服务器”;PHP脚本与其他脚本进行通信


How to make a "server" PHP script communicate with other scripts

服务器脚本将连续运行。

其他脚本是正常的网站,应该能够与服务器脚本进行通信。

我遇到过棘轮(https://github.com/cboden/Ratchet),尝试了以下示例:http://socketo.me/docs/hello-world它起作用:D

但是客户端需要javascript。我想用PHP将请求发送到服务器,因为消息是linux命令,我不希望网站访问者能够将linux命令发送到我的服务器脚本。此外,只应考虑来自"localhost"的脚本的消息。

用棘轮可以做到这一点吗?或者有其他解决方案吗?

Ratchet不提供客户端。我会为您的php-websocket客户端查看php-websocket。

为了确保客户端连接来自Ratchet中的localhost,请更改Push Integration教程中的以下代码:

// 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
);

您需要创建一个代理PHP脚本,该脚本将处理javascript请求并将其转换为棘轮脚本的CLI命令。

相关文章: