与在 PHP 中运行的应用程序的接口? [英] Interface with running applications in PHP?

查看:34
本文介绍了与在 PHP 中运行的应用程序的接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何方法可以通过 PHP 与正在运行的控制台程序(最好在 Linux/Debian 上运行)进行通信.我目前正在尝试为一个小的(现有的)控制台 Java 程序创建一个 Web 界面,但我不知道是否有任何方法可以做到这一点.我可以注入"一段代码,比如说一个远程控制模块,然后使用它通过 PHP远程控制"脚本吗?(如果现有的 .jar 文件不被更改/只是注入,不重新编程,那就太好了)

I would like to know if there is any way to communicate with a running console program (preferably running on Linux / Debian) via PHP. I am currently trying to create a webinterface for a little (existing) console Java program and I have no idea if there is any way I could do this. Could I "inject" a piece of code, lets say, a remote control module, and then use this to "remote-control" the script via PHP? (It would be great if the existing .jar file wouldn't be changed / just injection, no reprogramming)

感谢每一条建议!

推荐答案

如果正在运行的程序没有通讯接口,那么就无法与之通讯.但是,如果确实如此,那么答案很大程度上取决于程序如何接收外部输入.

If the running program has no communication interface, then you can't communicate with it. If it does however, then the answer very much depends on how the program receives external input.

如果程序包含网络监听线程(守护进程),那么您可以使用 CURL 或 PHP 的原始套接字在环回接口上与其通信.

If the program contains a network listening thread (daemon), then you can communicate with it on the loopback interface using CURL or raw sockets from PHP.

与程序通信的其他方式是共享对文件的访问(PHP 写入文件,Java 读取文件)或通过数据库.

Other ways of communicating with the program would be to share access to a file (PHP writes the file, Java reads it) or via a database.

数据库将是最佳选择 - 它是线程安全的,PHP 和 Java 都具有出色的 MySQL 支持(Java 通过 JDBC).

The database would be the best option - it is thread safe and both PHP and Java have excellent MySQL support (Java via JDBC).

但是,如果您不需要实际与正在运行的程序进行交互,只需要启动/停止/重新启动它,您可以使用 PHP 中的 system() 函数来完成.

If, however you do not need to actually interface with the running program only merely need to start/stop/restart it, you can do this with the system() function in PHP.

这篇关于与在 PHP 中运行的应用程序的接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆