1

I am using PHP 5.5 with Apache 2.4 and Java 8. Now I want to call the function within a Java JAR file. I search the internet about the PHP Java bridge. I have found a JavaBridge.Jar file for the SourceForge, but I don't know how to make it works. So how can I use PHP Java Bridge. I found by Google saying it may use PHP exec() to execute the Java function, however, this method seems need to open the JVM each time. So I am wondering whether it has a better method to call function in JAR.

1
  • why do you want to use Java & PHP at the same time ? Commented Jul 14, 2014 at 2:49

1 Answer 1

1

You have to have the jvm running at some point if you want to execute your java function - you are correct that running the jvm many times is not ideal.

PHP's exec call simply runs an external program (resident on the server). If you write a complete Java application, your program could then call whatever function you want. This, of course, will result in the jvm having to start for each instance of the program (someone can correct me if there will be pooling, but I suspect not).

A better solution would be to work out a way to keep a single java program running indefinitely, and communicate between your PHP code and that one instance of your java program (which does the function calling). A pretty straight-forward way to do this would be with a Socket (PHP) that connects to another Socket (Java "ServerSocket"). Build a java application as a 'server' that accepts requests from your PHP 'client'.

Google has been very helpful to me in the past in getting started with network communication with java/etc.

The library that you mentioned looks like it does something like this for you, but it looks like you will need to have some sort of java application available to connect to - not just a raw jar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.