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

查看:144
本文介绍了与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中的原始套接字在Loopback接口上。

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).

如果您不需要与正在运行的程序实际接口只需要启动/停止/重新启动它,则可以使用system() PHP中的功能。

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天全站免登陆