PHP <--> Java daemon

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

PHP <--> Java daemon

Post 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!
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

Well, if java fits better for your task, what's the need of php? ;)
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

Post 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.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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.
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

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

Post 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.
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

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

Post 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.
brighama
Forum Newbie
Posts: 11
Joined: Sun Apr 01, 2007 10:42 am

Post by brighama »

Hmm. Ok, I'll look into it further...

Thanks!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

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