I have a java program that has a healthy Java API, but I want build a primitive interface between my java application and a php script as those are the requirements of my project.
My first attempt was to write a PHP script that ran an passthru function to run the jar. i.e.
passthru("java -jar myjarfile param1 param2 param3")
This worked but proved to be quite slow because the jar file had to be launched and executed etc.
My next attempt was to create a servlet on Tomcat7 and interface it with PHP by usin 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 was loading 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 have my java program running in a jvm and interact with it using PHP?
Thanks