Make PHP execute and communicate with a Java application on a web server

前端 未结 4 1896
你的背包
你的背包 2021-01-12 09:10

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

相关标签:
4条回答
  • 2021-01-12 09:48

    Google App Engine allows to host Java (and Python) web applications. The SDK and the basic account is free of charges. With the SDK, you could develop and test the application locally and then simply deploy to App Engine (NetBeans and Eclipse plugins are available).

    Then the PHP app could send the data in a HTTP POST to the Google App Engine application and get the result in the response data.

    Or the data is stored first in a database blob and a processing job is put in a task queue (a 'message queue'). This has the advantage that the PHP client request will return immediately after the data has been POSTed. Then, the PHP application could poll for the result data while Google App Engine processes the image. The PHP side would be more responsive this way.

    0 讨论(0)
  • 2021-01-12 09:57

    I think your best bet here is with your java app running as cron(or a deamon) that can load the file details from the database. This will require a (one or more) page-refresh on the users part after the generation is complete, at which point your script can recall the image from the database/filesystem.

    I do not think you will be able to do this in real-time due to timeout restrictions on the PHP webpage. However, you could write a java applet that can take the file and process it before sending it to the server (or depending on how you intend to use it, perhaps you do not need to upload it after the transformation?).

    0 讨论(0)
  • 2021-01-12 10:06

    Wouldn't it be easier to make your java app a web app, that PHP could call via an url in wich he would put the url of the image so java can download it?

    like http://yourjavaserver/imageprocessing?imgurl=IMAGE_URL

    and the java servlet would reply with the image file itlsef.

    You can look for "java hosting" on google, to find a host for this, but it's more expensive than PHP hosting. Maybe the best choice would be to get a dedicated server which could host both PHP and java applications...

    0 讨论(0)
  • 2021-01-12 10:13

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

    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.

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

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

    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.

    0 讨论(0)
提交回复
热议问题