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

user1198778
  • 379
  • 1
  • 4
  • 10

1 Answers1

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

Community
  • 1
  • 1
Ahmed Qasid
  • 293
  • 2
  • 9