使PHP执行并与Web服务器上的Java应用程序通信 [英] Make PHP execute and communicate with a Java application on a web server

查看:165
本文介绍了使PHP执行并与Web服务器上的Java应用程序通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java应用程序,它将图像作为输入并输出另一个图像。我有一个热门主机的网站(PHP + MYSQL主机)。我想在网站上用PHP创建一个页面,用户可以上传一个图像,然后将图像传递给Java应用程序。

I have a java application that will take the image as an input and output another image. I have a website with a popular host (PHP+MYSQL Hosting). I want to create a page on the website with PHP with a form where a user can upload an image which will then pass the image onto the Java application.

我是什么计划做的是当用户上传图像时,它存储在Web服务器上的文件夹中。然后,我将调用服务器上的java应用程序,将图像的url作为参数传递,然后java应用程序将输出另一个图像,比方说,输出到结果文件夹。执行后的PHP页面将在浏览器上显示结果图像。

What I am planning on doing is when then user uploads the image, it gets stored in a folder on the web server. I will then call the java app on the server passing the url of the image as an argument and then the java app will output another image, let’s say, to a result folder. The PHP page after the execution will then display the result image on the browser.

现在我的问题是:
是否可以在流行的webhosts上执行java应用程序(例如我的是WebHostingBuzz.com)?

Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?

java应用程序相当繁重,因为它进行了大量的图像处理。我应该将Java应用程序卸载到另一个Web服务器吗?如果有,是否有任何服务将运行我的Java应用程序?

The java app is fairly heavy as it does a lot of image processing. Should I offload the java app to another web server? If yes, are there any services that will run my java app?

(可选)这是我的Java应用程序的演示,我不想存储图像人上传。有没有办法可以直接将上传的图像传递给java应用程序并输出直接生成的图像而不是将其存储在Web服务器上?我更喜欢这个,因为如果图像很大,我可以让PHP在超时后停止执行。

(Optional) It’s a demo of my java app and I don’t want to store the images people upload. Is there a way where I can directly pass the uploaded image to the java app and output the image generated directly instead of storing it on the web server? I would prefer this because, if the image is big, I can make PHP stop the execution after a timeout.

我如何与PHP的Java应用程序通信以获取信息在执行时,例如当PHP调用java应用程序时,页面必须等到应用程序完成处理?我希望java应用程序向PHP页面发送一个响应,说明处理已完成并且页面被重定向或相应刷新。

How do I communicate with the java app from PHP for info on its execution, for example When PHP calls the java app, the page has to wait till the app finishes processing? I want the java app to send a response to the PHP page saying that the processing is completed and the page is redirected or refreshed accordingly.

我希望你明白这个想法,请建议我可以使用的技术来实现这一点,如果你有更好的想法,请发布它!
谢谢!

I hope you get the idea, please suggest the technologies that I can use to implement this and also if you have a better idea, post it! Thanks!

推荐答案


现在我的问题是:是否可以执行java app在流行的webhosts上(例如我的是WebHostingBuzz.com)?

Now my questions are: Is it possible to execute java apps on popular webhosts (for example mine is WebHostingBuzz.com)?

技术上可行。但托管必须在主机上安装JRE,并为PHP用户提供足够的操作系统级和文件系统级权限。所以你真的依赖托管他们是否提供这个机会。最好是联系他们的支持团队并询问它。

It's technically possible. But the hosting has to install JRE at the host and give the PHP user sufficient OS-level and filesystem-level permissions. So you're really dependent on the hosting whether they provide this opportunity. Best is to just contact their support team and ask it.

如果支持,你可以使用 shell_exec()

If it is supported, you could just use shell_exec().

$result = shell_exec("java -jar /path/to/imageprocessor.jar " + $imagepath);
if ($result) {
    // Shell execution succeed.
} else {
    // Shell execution failed.
}

对于异步通信/后台处理,客户端必须触发一个ajaxical请求。

For asynchronous communication / background processing, the client has to fire an ajaxical request.

如果不支持,请考虑将Java移植到PHP。 GD图像库具有很多可能有用的功能。

If it is not supported, consider porting Java to PHP. The GD image library has pretty a lot of functions which may be of use.

这篇关于使PHP执行并与Web服务器上的Java应用程序通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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