tags:

views:

158

answers:

6

We have a php setup for our web pages that is secure with HTTPS. The web app talks to a DB but we also want it to talk to a java server we have.

The java server is a standalone java application (not web). We simply want a callback action after the PHP page finished writing to the DB done in the java server. What is a good way for this php page to talk to the java program to get something done?

+2  A: 

Probably via a TCP/IP connection. If your Java application runs a server, then the PHP script can connect and send a message informing the Java app that the DB has been written to.

Jon Benedicto
+4  A: 

I usually recommend against quick and dirty but here : You can dump data in a file if it can be asynchronous. Then a cron job from java, checking for that kind of file at a regular interval, do the specified command.

For example, you can dump the word ExecuteCmd1 in a file. The java thread reads it, interprets it and choose that he must execute the method or class with the same name.

You can do the same thing over to go back to php.

Silence
I'd agree with this direction. It looks like you just need to trigger an action. The php script could even build Java code to be executed in-line.
Dooltaz
@Dooltaz : hmmm don't add unnecessary coupling.... if he later needs to change java to another language... he'll have to rewrite a great part of the code
Silence
A: 

Google Protocol Buffers Not so much dirty, but works, and works well, regardless of which launguage you use.

FlappySocks
A: 

You can try the PHP/Java bridge. I used it a while ago to use Java logic inside Typo3, a PHP CMS.

My advice, whether you use the bridge or not: make sure you know where the errors come from if something doesn't work. Check both PHP and Java logs. Be verbose if an exception occurs.

lbp
+1  A: 

Do a quick and dirty JSON RPC from PHP to Java. You could probably get it up and running in one cup of coffee.

Use CURL on php (http://php.net/curl) and json_encode() to POST a json string to your Java server. (scroll down and find the curl wrapper class that someone wrote in the comments. It's easy.)

Use JSON (http://www.json.org/java/) in Java to decode it and use it immediately. Send your response back in JSON too.

I had a similar XML RPC system running in production for years. PHP -> IP -> Java works great.

Vineel Shah
A: 
  1. How much data do you need to transfer?

  2. How many requests per second?

  3. Does the Java application have to handle the request immediately, or is it enough to handle the request in a few minutes?

  4. Does the Java application need to return data to the user's browser?

If the answers to questions 3 and 4 are no and no, you could just create a database table for the jobs, have the PHP app insert a new job, and have the Java app poll the job table every minute or so.

mikaelhg
1) tens of bytes each time 2) 100 requests per second 3) it needs to be handled within 10 seconds for each request 4) No data is returned to the php side. What is the solution?
erotsppa
Is the 10 seconds a hard requirement, or something that someone just threw out there? Sorry, I don't check this site daily, so your problem has been probably already been solved.
mikaelhg