Running Java and PHP Applications

I have a Java program with a healthy Java API, but I want to build a primitive interface between my java application and php script, as these are the requirements of my project.

My first attempt was to write a PHP script in which the passthru function was run to run the jar. i.e.

passthru("java -jar myjarfile param1 param2 param3")

This worked, but turned out to be rather slow, because the jar file had to be launched and executed, etc.

My next attempt was to create a servlet on Tomcat7 and link it to PHP using the curl () command. i.e.

curl(http://myserver/mywebapp/myservlet?p1=param1&p2=param2&p3=param3);

This had excellent performance, but the servlet was very unstable and crashed after about 5 minutes (I loaded the server with about 1 request every 10 seconds)

I come to Stack Overflow asking: am I doing this right? Is there a better way? How can I run my java program in jvm and interact with it using PHP?

thank

+5
source share
2 answers

There is a world of difference between the Java method of processing things and the PHP method of processing things.

PHP basically runs each script from start to finish for each request, which is a very important programming method. On the other hand, Java typically processes things with modules that remain in memory for many more than one request. To integrate the two, you need to consider more than “function calls”, you need to think about how these two environments can be hidden cleanly.

java PHP- , Java PHP. , Java, PHP. Tomcat ( - ) . , PHP - Java, Java ( PHP ).

+3

, , JAR, PHP Java . Java- PHP . , , , . .

+1

All Articles