Page 1 of 1

Interaction between PHP -> Java -> MySQL DB

Posted: Wed Nov 15, 2006 10:15 pm
by Jessca
Hello. I have two "applications" which need access to a MySQL DB simultaneously, and which both need to be up-to-date. One is a Java application which holds certain often-changing data in memory, and writes to the MySQL DB on a timer, and when any large changes are made. The other is HTML/PHP based webpage, and thus obviously doesn't hold any information in memory. Without going deeply into it, the Java application can't update the DB on every change, so my idea is that my webpage would query the Java application when data was requested, and the Java application would respond with data in memory (if it was more up-to-date), or it's own query to the MySQL database.

My question, however, is about the best way to go about doing this. Since the php code isn't "running", so to speak, but rather compiled and performed at runtime, then closed, I can't see a way to have the webpage wait for a response to any requests from Java. Would I necessarily need some type of running application, written in php or java, such that I could wait for responses to queries? If so, what would be the best way to query that program? In either case, what type of interface would be best to be used for this purpose? I can run a telnet server from the Java application via a ServerSocket which waits for requests, but then I'm not sure of the best way to communicate through that medium without opening an actual telnet session.

I know this is alot to ask, and rather open-ended, so to speak, but any suggestions whatsoever, even very minor ones, would be greatly appreciated.

Thanks so much for your time!,
-Jess

[Edit for clarity]

Just to be clear, since I know I can get a little caught up in things... My questions is how to best query a Java application, and wait for a response from the JVM with a webpage. Or, in other words, the most common practice for communicating between two programs. Thanks again!
-Jess

Posted: Thu Nov 16, 2006 2:07 pm
by Jessca
I can also supply more information, and whatnot, if it's desired. I'm just not sure what direction to go with this... so any help whatsoever is appreciated.

Thanks so much,
-Jess

Posted: Sat Nov 18, 2006 2:25 am
by Jessca
I'm still unable to solve this problem, so if anyone is able to give me any advice, whatsoever, please don't hesitate, as it would be greatly appreciated.

Thanks, so much!,
-Jess

Posted: Sat Nov 18, 2006 7:19 am
by feyd
Unless your Java application is listening to a port, responds to console commands, or is run by PHP I seriously doubt this is possible.

Posted: Sat Nov 18, 2006 1:55 pm
by Jessca
It is listening to a port. That's what I had in mind... I could have sworn I mentioned that, my apologies. --- There are still a number of problems, including the best way to wait for information on the website's end. Do you have any suggestions, or even any terminology so I can find other suggestions myself elsewhere?

Thanks so much for responding!,
-Jess

[Edit]

The idea I had would be to let Java listen on a given port, (which I've already implemented), and allow php to somehow request data through that port and wait for a response (which I'm not sure how to implement). I can do the whole process on the Java end, I'm just not sure how to do it on the php-end. I know there are examples of other applications interacting with eachother out there, and likewise I'm sure there are examples of a website interacting with an application in a similar manner... I'm just not sure how they do it, or where to find out how. Even terminology for that would be great, as I'm sure I could find a wealth of information on google if I had something to look for.

Thanks, so much, once again!,
-Jess

Posted: Sat Nov 18, 2006 5:43 pm
by Ambush Commander
PHP is not multithreaded and generally is not used to create daemons. It's a "Make a request, PHP gets executed" model: PHP cannot get data itself.

Posted: Sun Nov 19, 2006 4:37 am
by Popcorn
You could look in PayPal's dev kit for PHP which connects and retrieves info using sockets:
https://paypal-toolkit.codebase.ebay.co ... p-0.51.zip
particularly global_config.inc.php

The code is simple enough, if not tight, but don't look for PayPal to offer any understandable documentation

Posted: Sun Nov 19, 2006 8:41 am
by Jessca
Hey. I just glanced over the code you mentioned, but it looks like exactly what I was looking for! Thanks so much to both of you! You've been a big help!

Thanks so much,
-Jess