What is the best/fastest way of calling java jar from php with passing large text? -


this scenario: have php script builds html , echoes browser. before html echoed, need call executable java jar file , pass html process , return php echoed out.

the way can come save html temporary file, pass java file name, let modify , load again in php. i'm guessing can quite slow , requires file being written disk, read, modified, written again , read again.

my question this: in given scenario there faster way of passing java html file , returning php?

my current stack: apache 2.4, php 5.4.7, java 7, os: ubuntu

i've used marc b suggested solution , since there no clear example of particular situation online, i'm pasting php , java code in case needs in future:

php code:

<?php  $process_cmd = "java -jar test.jar";  $env = null; $options = ['bypass_shell' => true]; $cwd = null; $descriptorspec = [     0 => ["pipe", "r"], // stdin pipe child read     1 => ["pipe", "w"], // stdout pipe child write     2 => ["pipe", "w"]  // stderr file write ];  $process = proc_open($process_cmd, $descriptorspec, $pipes, $cwd, $env, $options);  if (is_resource($process)) {      //feeding text java     fwrite($pipes[0], "test text");     fclose($pipes[0]);      //echoing returned text java     echo stream_get_contents($pipes[1]);     fclose($pipes[1]);      //it important close pipes before calling     //proc_close in order avoid deadlock     $return_value = proc_close($process);      echo "\n command returned $return_value\n"; }  ?> 

java code:

package test;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader;  public class test {      public static void main(string[] args) throws ioexception {          bufferedreader br = new bufferedreader(new inputstreamreader(system.in));          string input;          while ((input = br.readline()) != null) {             system.out.println(input + " java test string ");         }      }  } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -