简体   繁体   English

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

[英]How to make a “server” PHP script communicate with other scripts

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 我遇到了棘轮( https://github.com/cboden/Ratchet ),试过这里的例子: http//socketo.me/docs/hello-world它的工作原理:D

But the client needs javascript. 但客户端需要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. 我想用PHP将请求发送到服务器,因为消息是linux命令,我不希望站点访问者能够将linux命令发送到我的服务器脚本。 Also, only messages from scripts from "localhost" should be taken into consideration. 此外,只应考虑来自“localhost”脚本的消息。

Is it possible to do this with Ratchet? 使用Ratchet可以做到这一点吗? Or are there other solutions for this? 或者还有其他解决方案吗?

Ratchet doesn't offer a client. Ratchet不提供客户服务。 I would look at phpwebsocket for your php websocket client. 我会看看你的php websocket客户端的phpwebsocket

To ensure that client connections come from localhost in Ratchet, change this bit of code from the Push Integration tutorial: 要确保客户端连接来自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命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM