1

I am getting user input from a website, though PHP, the Java program is running on my server, it takes the user input, does some magic and spits back a response in the form of an HTML page.

The problem that I am having is that I only want to start the java program once, because there is some heavy lifting that needs to be done only once. But then I want to keep the Java running and just get it to react to the input from the website.

My method to pass information from PHP is by calling a command prompt command, with the appropriate args. Now obviously I can't use args after the program started.

I need some sort of Buffer or Input Stream, something that will give me pretty much instantaneous response time.

Thank you in advance

1
  • Can you just add a Tomcat to your setup to run your java app as a servlet? Commented Mar 6, 2014 at 21:46

1 Answer 1

2

I can think of three alternatives:

  1. Using sockets. You can make your java application become some sort of a "server" that receives request and then "respond" to them. The same way your HTTP server works (but of course on a different port). This article explains how to work with java sockets. (searched for:java socket programming) And this one explains working with sockets from php (searched for:php socket programming)

  2. Making your java application single-instance check this to save start-up time, but this way you will have to write response in files or something.

  3. Put your java code in a servlet, run it inside a web container, and redirect the requests from your php page to the servlet. refer to ths question

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

2 Comments

I would suggest answer 3.
ended up going with a socket, works like a charm for what I need, thank you

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.