如何获取 PHP 脚本来从已运行的进程发送和接收数据?
我正在尝试为网络创建一个简单的 AJAX 到 Telnet 客户端。 我这样做可能是在重新发明轮子,但这对我自己来说是一个学习项目。 目前我还没有写任何东西,我只是想把这个想法融入我的大脑中。 它不一定必须是 PHP。
如果我有一个支持已在其自己的进程中运行的多个连接的 telnet 客户端,如何获取在客户端浏览器要求能够与客户端通信时触发的 PHP 脚本?
例如,我希望 PHP 脚本能够告诉已经运行的进程它是哪个客户端,并从 telnet 进程接收任何新数据。
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.
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?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 PHP,您谈论的是通过 shell 进行交互,对吗? 这完全取决于您尝试连接的 telnet 客户端以及它支持的 CLI 选项。 打开一个流可能需要让每个 telnet 会话将其 STDIO 输出到文本文件,然后让 PHP 读取该文本文件并显示“差异”。
使用 PHP 中的 Fsockopen(),您实际上不需要与另一个程序交互,您可以直接在 PHP 中运行套接字命令并在那里获取结果。
PHP:Fsockopen
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'.
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
我将创建一个作为守护进程运行的 telnet 客户端。 它将负责创建和维护 telnet 会话并缓冲任何接收到的数据。
然后,您的 PHP 脚本可以使用 TCP 连接或 Unix 套接字,通过 PHP 套接字 API。
吉姆.
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.
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.
Jim.
即使连接需要持久?
编辑:没关系,我想我有一个想法。
我将自己编写客户端部分,但如果它也可以充当服务器,PHP 通过连接到它并提供相关数据来进行调用,以便它可以找出用户需要哪个连接......作者:George I我想我已经明白了!
edit2:吉姆就是这么说的。 谢谢吉姆。
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!
edit2: That's what Jim said. Thanks Jim.