Interaction between PHP -> Java -> MySQL DB

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Jessca
Forum Newbie
Posts: 5
Joined: Wed Nov 15, 2006 9:33 pm

Interaction between PHP -> Java -> MySQL DB

Post 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
Last edited by Jessca on Thu Nov 16, 2006 2:11 pm, edited 1 time in total.
Jessca
Forum Newbie
Posts: 5
Joined: Wed Nov 15, 2006 9:33 pm

Post 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
Jessca
Forum Newbie
Posts: 5
Joined: Wed Nov 15, 2006 9:33 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Jessca
Forum Newbie
Posts: 5
Joined: Wed Nov 15, 2006 9:33 pm

Post 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
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
User avatar
Popcorn
Forum Commoner
Posts: 55
Joined: Fri Feb 21, 2003 5:19 am

Post 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
Jessca
Forum Newbie
Posts: 5
Joined: Wed Nov 15, 2006 9:33 pm

Post 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
Post Reply