如何获取PHP脚本以从已运行的进程发送和接收数据?

时间:2021-05-03 07:12:35

I'm trying to create a simple AJAX to Telnet client for the web. I may be re-inventing the wheel by doing this, but it is a learning project for myself. At the moment I haven't written anything, I'm just trying to get the idea wrapped around my brain. It doesn't necessarily have to be PHP.

我正在尝试为Web创建一个简单的AJAX到Telnet客户端。我可能会通过这样做重新发明*,但这对我自己来说是一个学习项目。目前我还没有写任何东西,我只是试着让这个想法缠绕在我的脑海里。它不一定是PHP。

If I have a telnet client that supports multiple connections already running in its own process, how do I get a PHP script that fires off when the client-browser asks to be able to communicate with the client?

如果我有一个支持已在其自己的进程中运行的多个连接的telnet客户端,那么当客户端浏览器要求能够与客户端通信时,如何获取一个启动的PHP脚本?

For instance, I want the PHP script to be able to tell the already running process which client it is and receive any new data from the telnet process.

例如,我希望PHP脚本能够告诉已经运行的进程它是哪个客户端并从telnet进程接收任何新数据。

3 个解决方案

#1


1  

For PHP, your talking about interfacing through the shell right? It would all depend on the telnet client you are trying to hook up with, and what CLI options it supports. Opening a stream to this would probably require having each telnet session outputting its' STDIO to a text file, and then having PHP read that text file and displaying the 'difference'.

对于PHP,你谈到通过shell接口吧?这完全取决于您尝试连接的telnet客户端,以及它支持的CLI选项。打开一个流可能需要让每个telnet会话将其'STDIO输出到一个文本文件,然后让PHP读取该文本文件并显示'差异'。

With Fsockopen() in PHP, you really don't need to interface with another program though, you can run socket commands directly in PHP and get the results there.

使用PHP中的Fsockopen(),您实际上不需要与另一个程序接口,您可以直接在PHP中运行套接字命令并在那里获得结果。

PHP:Fsockopen

#2


1  

I'd create a telnet client that runs as a daemon process. It would be responsible for creating and maintaining the telnet session and buffers any received data.

我将创建一个作为守护进程运行的telnet客户端。它将负责创建和维护telnet会话并缓冲任何接收的数据。

Your PHP script could then use a TCP connection, or a Unix socket to communicate with your telnet client daemon process using the PHP sockets API.

然后,您的PHP脚本可以使用TCP连接或Unix套接字使用PHP套接字API与您的telnet客户端守护程序进程通信。

Jim.

#3


0  

Even if the connection needs to be persistent?

即使连接需要持久化?

edit: nevermind, I think I have an idea.

编辑:没关系,我想我有个主意。

I'll be writing the client part myself, but if it could also act as a server that PHP makes calls to by connecting to it and giving relevant data to so that it can find out which connection the user needs... by George I think I've got it!

我将自己编写客户端部分,但是如果它也可以充当PHP通过连接到它并提供相关数据来调用的服务器,以便它可以找出用户需要的连接...由George I我想我已经拥有了!

edit2: That's what Jim said. Thanks Jim.

编辑2:这就是吉姆所说的。谢谢吉姆。

#1


1  

For PHP, your talking about interfacing through the shell right? It would all depend on the telnet client you are trying to hook up with, and what CLI options it supports. Opening a stream to this would probably require having each telnet session outputting its' STDIO to a text file, and then having PHP read that text file and displaying the 'difference'.

对于PHP,你谈到通过shell接口吧?这完全取决于您尝试连接的telnet客户端,以及它支持的CLI选项。打开一个流可能需要让每个telnet会话将其'STDIO输出到一个文本文件,然后让PHP读取该文本文件并显示'差异'。

With Fsockopen() in PHP, you really don't need to interface with another program though, you can run socket commands directly in PHP and get the results there.

使用PHP中的Fsockopen(),您实际上不需要与另一个程序接口,您可以直接在PHP中运行套接字命令并在那里获得结果。

PHP:Fsockopen

#2


1  

I'd create a telnet client that runs as a daemon process. It would be responsible for creating and maintaining the telnet session and buffers any received data.

我将创建一个作为守护进程运行的telnet客户端。它将负责创建和维护telnet会话并缓冲任何接收的数据。

Your PHP script could then use a TCP connection, or a Unix socket to communicate with your telnet client daemon process using the PHP sockets API.

然后,您的PHP脚本可以使用TCP连接或Unix套接字使用PHP套接字API与您的telnet客户端守护程序进程通信。

Jim.

#3


0  

Even if the connection needs to be persistent?

即使连接需要持久化?

edit: nevermind, I think I have an idea.

编辑:没关系,我想我有个主意。

I'll be writing the client part myself, but if it could also act as a server that PHP makes calls to by connecting to it and giving relevant data to so that it can find out which connection the user needs... by George I think I've got it!

我将自己编写客户端部分,但是如果它也可以充当PHP通过连接到它并提供相关数据来调用的服务器,以便它可以找出用户需要的连接...由George I我想我已经拥有了!

edit2: That's what Jim said. Thanks Jim.

编辑2:这就是吉姆所说的。谢谢吉姆。