tags:

views:

1473

answers:

13

PLEASE NO FLAMING!

I really would love a few objective opinions about the issue. I have a project that has been strongly developed in PHP but have clients that are concerned that Java would be a better solution. I know sites such as Flickr and Digg are run on PHP, but I am concerned that PHP's lack of a running environment may destroy my project.

Example. PHP (that I know of) does not have an easy way to fork another process, nor is there an easy way to start a deamon to run background processes (cron jobs are a little ugly).

I would hate to rewrite a great piece of software, so I am in need of some solid advice.

+6  A: 

I probably won't be entirely fair since I love php, but it's an incredibly mature and widespread language and definitely good for enterprise level applications. Even if it was a little bit inferior as far as performance to java the gap would be minimal - I don't think that's the case though.

For sure not worth it to rewrite your app in java.

Svet
+30  A: 

Well if you know Digg and Flickr are run on PHP then you already know the answer. I'll add a few more: Wikipedia, Facebook and Yahoo.com. If you believe your site will even come close to those, then good luck...

What you call a "lack of running environment" can actually be considered a strength - errors are contained in self running instances and do not propagate to other shared resources, making for a more stable environment. Sure, you have to deal with sharing common data in an efficient manner, but that's part of the game. Caching, lazy loading and other techniques help solve that part of the equation.

Also, it's quite common to mix PHP and Java using a bridge, where Java can handle backend tasks that require a longer runtime or specific optimizations.

Eran Galperin
This is sort of the same flawed argument as before. Just because you can scale doesn't mean you can solve complex problems very well. Digg solves the "I want to mindlessly vote on links" problem. Enterprise apps have complex workflows and complex datastructures.
BobbyShaftoe
I'm not sure where are you going with this. What exactly limits PHP from solving the same problems Java does? and the examples I mentioned are some of the most complex infrastructure on the web. If you have counter examples, I would like to hear them.
Eran Galperin
I don't understand the whole idea of "enterprise" being somehow more complex or needing more scale. It's frequently the opposite. A good example of PHP-based "enterprise" software is SugarCRM.
pbreitenbach
A: 

I really can't imagine having problems with PHP scaling to enterprise level when it scales just fine for some of the largest sites on the web. You mentioned Digg and Flickr but there are many more like more Yahoo owned properties and i just heard the other day wikipedia.

I think this question comes up a lot because there just aren't as many PHP gurus in mainstream american as there are Java and .NET gurus. Enterprise software tends to be written in those languages because so many of the employees already know them.

Now this might not apply to the larger cities. I imagine it isnt to hard to find good PHP devs in Silicon Valley or New York but not so much in my area (Cleveland.)

JoshReedSchramm
+4  A: 

It sounds like you are mostly concerned about the lack of some of this functionality in the environment.

It's not all wrapped together like in the Java runtime, but here's how you can fork in php:

Here's one way how to fork:

$arg1 = 'argv1';
$arg2 = 'argv2';
system("php ./script2.php $arg1 $arg2 &");

http://www.php.net/system

or

$output = shell_exec('script2.php &');

http://www.php.net/shell_exec

And as you've already stated, cron-jobs can do background/periodic processing.

Otherwise it sounds like you have a communication issue with your clients. What exactly are their concerns? Are the clients other software engineers? Are they willing to pay for the conversion to Java? Are they just new to php? Are they non-tech savvy and have heard that "Java is cool"?

If performance does matter, what research have you done in optimizing php? Have you looked at caching php opcodes to improve performance? Just google php cache opcode for more info.

Doug T.
PHP can actually fork, which is different from using exec() or system(): http://www.php.net/manual/en/function.pcntl-fork.php
Frank Farmer
+8  A: 

I wrote an enterprise-level application that generates a significant amount of revenue, all in PHP.

I do use things such as cron jobs to do background processing, "forking" through exec to spawn other processes that I monitor from an outside resource (such as a database or an xml repository.)

There are some issues that have been addressed in recent versions of PHP and various products from Zend, such as scaling, clustering, etc. This, in my opinion, was a positive step for PHP.

However, from a programming perspective, PHP lefts a lot to be desired. Consistency is lacking in function names, duck typing is not a good thing from my perspective, the pseudo object oriented support is frustrating, etc.

But -- in short -- yes, it is suitable for enterprise-level applications to use PHP when used correctly with reasonable standards and a good amount of thought put into your design.

Good luck!

Ian P
A: 

I may be concerned with the portability of the product and i will explain myself. Do this application need to be accessible offline? Is there a possibility that someone want to run this apps without internet access ? if the answer is no, there should be no problem with PHP. But if it's yes, keep an eye at java/.net or other language that could do both Web and Windows (Linux or whatever) environment.

I also see a lot of "script kiddies" in php and a lot of "horror code". I know that there are a lot of project well written but without a good programming chart, it could go worse.

I don't want to do PHP bashing but just to trigger some questions.

David
It's not that difficult to run a small local server for offline php apps.
Joeri Sebrechts
OP was clearly talking about JSP, anyway which puts it an an equal disadvantage for "running offline" as you are still stuck with the requirement of setting up a local server.
Nolte Burke
+6  A: 

Can PHP handle enterprise level sites? Yes.

Handle as good as Java? No.

Whether it's worth rewriting or not depends on your features. We rewrote our project utilizing java threads and performance gain was around 10x, If you are asking will you gain any speed from converting php to java I would say most likely yes.

I would try to optimize php code as much as possible first, if it is not enough then go java.

(I love both php and java btw)

serg
I think a 10x performance improvement would be pretty rare. In general you should be able to get PHP performance in the same ballpark without too much effort.
pbreitenbach
Not unless your Java framework is horribly inefficient, or for apps in which the db server does 99% of the work.
Seun Osewa
A: 

I think that it really depends on the application. If you were making an enterprise level application that needed to do lots and lots of server side jobs, or something where speed was a primary concern, then converting parts of it to Java (or even a speed oriented compiled language like C if its a major concern) would be a good idea.

However, in terms of PHP being able to handle a more normal style website, that's very likely.

Also, I'd like a bit of clarification. Do you mean for Java to work as the backend of the site, actually taking a part in serving the HTML code for the pages, or do you mean for Java Applets to be embedded in the site for the client to interact with? That plays a big role in the decision, as I've seen it done both ways. I think that clientside, you would want to use Java or something similar for a realtime APP, as it puts much less strain on the server and will generally be smoother for the user to work with, not minding the Java Runtime that needs to be there.

Really, it all depends on the application. Choose the right programming language for the job. If you're running a more typical website, then PHP will do just fine. If you need to do some very specific things that rely on speed, a traditional programming language will probably work better on the backend. And you can always mix and match. ^_^

-Nicholas

Nicholas Flynt
A: 

You may not need to choose between PHP and Java, as the Caucho application server supports both Java and PHP. See here.

Alan
+1  A: 

That depends on your needs.

I would suggest that you evaluate both based on the following parameters

  1. Support for Encryption and Cryptography.
  2. Built in defense mechanisms against common hacker attacks.
  3. Third party library support, and quality of documentation therein.
  4. Ability to integrate your application, with both SOAP and REST based web services.
  5. Maturity and effectiveness of development tools like IDEs and debuggers.
  6. Load Balancing and Session fail over support.
  7. Available Web Development Frameworks and maturity of the same.

I am sure, there are others. But the bottom line is; when you are building enterprise applications, be ready for security audits, and make sure that the development platform you select, helps you in passing those.

The other thing is, invariably your application would need to talk to other apps within the enterprise. So be sure that your chosen platform has a mature and standards compliant web services stack, built in.

swapnonil
+3  A: 

Prefer java, not PHP:

"Because this is matter most of all if you want achieve code which: 1. Reliable 2. Understandable 3. Reusalbe "

http://dmitry-nikolaev.blogspot.com/2009/06/php-vs-java-from-developer-perspective.html

blackliteon
+1  A: 

Technically, PHP could support just about any "enterprise" task thrown at it. The problem you may run into is that your IT and other departments are reluctant to install and support something they are not familiar with. The barriers to using PHP and LAMP in the "enterprise" are almost entirely artificial.

pbreitenbach
A: 

Can enterprise application be written in php? No.

Explanation. If you are speaking about enterprise application you are talking about three tire system architecture. Database tire, middle tire and client tire. The middle tire should have distributed components if necessary but for large enterprise apps it is always necessery. Java have ejbs - distributed objects, Hibernate PHP is only scripting language for web apps. It cannot build middle tire with php other than web (distributed components for other clients than browser).

This is where this story ends! We cannot speak about enterprise application without distrusted components. With php you can build maybe a huge projects, but you cannot share the business logic with other clients than than browser. Someone could say you can use web services, but the services in php are not suitable for mission critical services.

Have you ever seen a bank application written in php? Have you seen bank components written in php? No.

PHP code can be so messy, so unstructured, so full of errors and thats why it cannot be used for enterprise. You can use continuous integration with phpundercontrol but it is not as java. There is no build so error could show up any time. Have you seen php classes that are reused and are using enterprise patterns? Very rarely. PHP programmers do not write abstractions, polymorphism and other OO staff.

And finally I will give you an example. "According to Oracle Corporation, by 2006 over 30,000 organizations had become Fusion Middleware customers, including over 35 of the world's 50 largest companies" wikipedia source. This technology is java based.

The other big player is IBM also using java. The rest of the market is taken by Microsoft. There is no room for php in bank sector, financial sector, military, governments, army It can only be used for web sites, but not distributed application, business inteligence.

There is a lot of thinks to discuss why php cannot be enterprise language.

darko petreski
So in short your answer is: PHP programmers are horrible coders, Java programmers are good.
kemp
One more reasnon. Do you know that PHP does not handle mathematics well! This formula is taken from official PHP siate:floor((0.1+0.7)*10) will usually return 7 instead of the expected 8
darko petreski
then no language does mathematics well when it comes to floating points... this floor drako petreski is referring too returns 7 in python and java as well.
t00ny
Java: float c = (float)Math.floor((0.1F + 0.7F) * 10F); System.out.println("" + c); will return 8.
darko petreski
Another issue. I have a big site written in php. It communicates with a payment processor for online payment. Once a time instead of sending the number 1200000 to the processor, the php from unknown reasons decided to convert the number to exponent and did it. It sent to the payment gateway an exponent!!. It took me several hours to find out what is going on. You cannot rely on dynamic variables when working with money.
darko petreski
@drako petreski: you're right for the java example, had forgot a cast when i tested it... but anyway i just wanted to raise the fact that floating point are always a problem eventually in any programming languages. but your right that dynamic languages tend to suck more in this area.
t00ny