Page 1 of 1
PHP <--> Java daemon
Posted: Wed Apr 18, 2007 9:19 am
by brighama
I have a PHP site that does a lot of intensive math operations for each request.
PHP was taking 300-500 msec per request.
My current solution: a Java daemon running in the background that PHP connects to over a socket.
This seems ideal; the socket overhead is minimal and I get the best of both worlds: Java's raw power and
PHP's page-serving speed. Now we average 60 msec per request.
My question: Is this wrong?
...I mean, I'm starting to shift more and more functionality into the Java daemon (e.g, database access stuff) because it is faster and more enjoyable for me to develop in. However, I haven't tested this in live deployment with any kind of load. Is there a fatal flaw in this type of setup?
Another question: Any suggested resources?
Thanks!
Posted: Wed Apr 18, 2007 9:41 am
by stereofrog
Well, if java fits better for your task, what's the need of php?

Posted: Wed Apr 18, 2007 10:15 am
by brighama
Well, I've heard that Java is a dog at serving web pages.
...but I see your point; if the java daemon is so great, why not shift the entire app into it? In other words, have PHP send the POST parameters over the socket and get back HTML? Seems ridiculous, but I don't fully get why it is a bad idea (besides aesthetics.)
I guess I also don't understand why Java sucks at serving web pages.
Posted: Wed Apr 18, 2007 10:24 am
by stereofrog
I meant, why don't you just install Tomcat or Resin and write the whole website in java? From what you've said, I don't see any reason to use php in your case.
And what do you mean by java being "expensive"? It's open source, just like php.
Posted: Wed Apr 18, 2007 10:36 am
by brighama
I meant, why don't you just install Tomcat or Resin and write the whole website in java? From what you've said, I don't see any reason to use php in your case.
Java websites are always slow. There are no large, successful websites written in Java that I am aware of.
Why is it so slow? I wish I knew
And what do you mean by java being "expensive"? It's open source, just like php.
Hosting a Java website costs about twice as much as a PHP site. It's a much more complicated system.
Posted: Wed Apr 18, 2007 10:45 am
by Chris Corbyn
brighama wrote:I meant, why don't you just install Tomcat or Resin and write the whole website in java? From what you've said, I don't see any reason to use php in your case.
Java websites are always slow. There are no large, successful websites written in Java that I am aware of.
Why is it so slow? I wish I knew
And what do you mean by java being "expensive"? It's open source, just like php.
Hosting a Java website costs about twice as much as a PHP site. It's a much more complicated system.
The JVM uses a lot of memory. You generally need better equipped servers. All in all I say just use Java though. It seems silly to use PHP purely for the purpose of taking the requests then relaying to Java.
Posted: Wed Apr 18, 2007 3:29 pm
by brighama
So, what do you make of this statement?
Java is a dog at serving web pages
Random bits of evidence:
* The vast majority of large, successful sites use PHP, not Java
* Friendsters shift away from Java
* "Java website" is synonymous with "slow-as-hell"
...am I misled?
Posted: Wed Apr 18, 2007 4:08 pm
by feyd
Provided the code is written well, Java runs circles around a lot of equivalent PHP code. It all depends on the specific code and the server settings. The combinations are endless however.
Posted: Wed Apr 18, 2007 5:19 pm
by brighama
Hmm.
I'm inclined to believe that.
But there must be some reason for "Java" == "slow-as-hell".
...are all Java programmers just unable to tune their servers correctly?
Posted: Wed Apr 18, 2007 9:21 pm
by feyd
I've never heard Java being equated to running slow from web developers. The only times I've heard references to its speed is from application developers, mostly those who write C/C++.
I've done both professionally.
Posted: Wed Apr 18, 2007 10:05 pm
by brighama
Hmm. Ok, I'll look into it further...
Thanks!
Posted: Wed Apr 18, 2007 10:32 pm
by Ambush Commander
The perception that Java = Slow largely stems from poorly written Java Applets and GUI applications, where initializing the runtime environment is painfully slow and the developers did not optimize properly to improve application response.
In a web context, these issues are mostly moot, due to the fact that the Java server is persistent, and web applications (in comparison to traditional apps) due not need to be blazing fast to give the perception of performance. My main problem with deploying Java based apps is that shared hosts don't support them! (as opposed to PHP, which is nearly universal) and that you have to compile your classes (which means somewhat slower development). Java is a pretty nice language with a very extensive standard library.