Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I always hear that PHP is for medium and small websites whereas .NET and Java for enterprise applications. My question is about PHP. Why is PHP not a good option for enterprise web applications? Is it because if the web application becomes bigger then PHP will be slower as it is an interpreted language?

I know that corporate world will choose .NET or J2EE because of the integration with their products and because of back end services, etc. However, if we just have PHP for building sites and web applications then how can we use it to perform well with big sites?

In short, Is there a relationship between the performance of PHP and the size of the website? What are the factors that make PHP not appropriate option for big sites?

share|improve this question
1  
Mediawiki (wikipedia's engine) is written in PHP and they made it perform well, but that doesn't prove anything. Could be a niche case. –  Michael K Mar 16 '12 at 13:29
2  
@MichaeltheGhost using sites in the Alexa top 50 (and maybe even a bit more) are poor examples because their volume is at such an extreme level that their solutions are highly customized and fine tuned for that level of traffic and aren't really the same technology anymore. –  Ryathal Mar 16 '12 at 14:05
1  
Facebook is using PHP too. Note also that this means things about scalability, not performance, but you know the difference, right ? Another example is freemobile, that rewrote its website in PHP from Java, for scalability reasons. –  deadalnix Mar 19 '12 at 10:11

6 Answers 6

Performance is probably not one of the factors. For a dynamic language, PHP actually performs pretty well; depending on the task, it might or might not beat other technologies. The application model simply is too different to compare it directly against Java or ASP.NET. Even if there is a measurable speed difference, it is not big, and it's probably linear, which means it can be solved by throwing more hardware at it. Also, the programming language itself is seldom the bottleneck - algorithms, database access, network bandwidth, and I/O in general are the usual culprits, unless you are writing somehing truly CPU-intensive.

Reasons for using ASP.NET or Java over PHP that are more likely include:

  • Platform integration. ASP.NET offers extensive integration with .NET and the underlying Windows OS.
  • General purposeness. PHP was designed specifically for the web, while .NET and Java are general-purpose platforms. Using Java or .NET, you can tack both desktop and web frontends onto the same shared code with little effort, while PHP isn't very suitable for writing desktop applications.
  • Code organization features. Java and .NET were designed for OOP from the start, while OOP in PHP is somewhat of an afterthought. PHP introduced namespaces very recently, and they are limited and clumsy compared to what .NET and Java have to offer. Enterprise-style programming usually relies heavily on OOP, which makes PHP the lesser candidate.

Another reason for the perceived effect is that PHP is free (as in beer) and ubiquitous - every cheap shared web hosting company has PHP in their standard package, but a .NET or Java server is going to cost you significantly more. Consequently, a huge mass of small websites uses PHP, not because it's the best tool for the job, but the only one at hand.

That's not to say PHP is unsuitable for large projects - it just doesn't go well with the 'enterprisey' kind of programming. Its strengths lie elsewhere, and if you can leverage them, you can just as easily build large-scale applications as you could with any other web technology.

share|improve this answer
2  
One little quibble, you can get ASP.NET shared hosting for the same price as LAMP shared hosting. The problem is the first places most people find when they're searching are ones marketed to small to mid sized business and are more expensive. –  jfrankcarr Mar 16 '12 at 16:39
    
+1, this is very well said & summarized. The bottleneck for most poor performing applications is rarely the language. –  GrandmasterB Mar 16 '12 at 19:01
    
true, but don't think Java is a solution - I've had the misfortune to use a lot of 'Enterprise' apps from companies like Oracle. Nearly all of them could be replaced with a PHP OSS app with little reduction in functionality, but a huge increase in performance and usabaility. –  gbjbaanb Mar 17 '12 at 15:08
1  
@gbjbaanb: Java is not a solution in this context because there is no problem. And whether something is open source or not has absolutely nothing to do with the topic. –  tdammers Mar 17 '12 at 20:36
    
@GrandmasterB yes and no. Java for instance, have a lot of internally synchronized primitives, and PHP don't. It require more discipline to write scalable java code. freemobile is a real world example of that effect. But, as the scalability isn't only dependent on the frontend (databases for instance are very important here) you need to think about it anyway. –  deadalnix Mar 19 '12 at 10:16

You're confusing traffic ("small and medium website" usually means a website with small to medium traffic), with the degree of business logic complication (simple website vs enterprise solution). In the second case performance is not the key factor.

For example Facebook is high traffic website, but it's not an enterprise app. On the other hand there are plethora of intranets based on Java application servers, that wouldn't be able to handle traffic of even midsize website.

Performance-wise PHP is not the best option, but it's not that bad either. Especially comparing with other dynamic languages. However, again, raw performance is not the most important factor. Creating high-traffic websites is more about optimizing for scalability on architectural level.


Why is PHP so despised by enterprise? There are few causes, first would be it's terrible security reputation. Second is that it perceived as a language for amateurs creating ugly, unmanageable HTML-PHP spaghetti code. That perception persist, even though there are mature MVC frameworks. I guess having PHP's original author argue that you don't need a framework doesn't help. Fact that these clueless amateurs with little to none programming skills call themselves "PHP programmers" doesn't help either. Third reason is that any experienced programmer will agree, that PHP is just badly designed as a language. You can clearly see that it was designed by a webmaster, while most modern dynamic languages were designed by post-grad academics specializing in compilers and language design.

And yes, in enterprise it's all about system integration, where PHP doesn't shine either. With enough effort you can create C modules. There is PHP-Java bridge, which is quite tedious to use. Beyond that you don't have much. Attempts to create Boost::PHP (integration with C++) have failed. PHP-clones running on JVM are far from being anything close to 100% compatibility with PHP (as a side note, there is no formal PHP language definition, the only reference is the default implementation).

share|improve this answer

No idea why people claim PHP is for small and medium websites. To best of my knowledge, this isn't true. I know some PHP backed websites that started small, then grew to be top100 websites in my country. They still use PHP and have no plans to change anything about it.

The thing, that might drive people to such conclusion is that in case of Java (and i guess also with .NET) application scalling is a term frequently brought up in documentation and literature. Most application servers out there support some form of clustering which allows rapid addition of "horsepower" along with the popularity growth. In case of PHP you have to build up cluster yourself. You can do it many ways, using different components and you have to know a bit or two about PHP inner workings. This probably makes people think, that with PHP single server (and thereby small or medium website) is a dead end for PHP.

share|improve this answer

I would say that the problems with PHP stem less from performance than a history of security vulnerabilities. While it's undoubtedly possible to write a web site of any particular size or complexity in PHP and still maintain security, as complexity increases, maintaining security tends to become more difficult.

Java, on the other hand, was designed with at least some ideas about security from day one. Although those don't fit entirely with most current deployment (the original thinking was primarily around applets, not servelets) that emphasis does mean its features tend to fit better with producing secure code. And, of course, it hasn't stood still either -- since applets are mostly a dead issue now, Java has been re-defined to emphasize the server-side role it now (mostly) occupies.

Since .NET at least tries to compete nearly directly with Java, it provides much the same sort of features and capabilities in this regard. You can argue (and adherents to both camps do) over whether Sun or Microsoft does a better job in this regard, but the simple fact that both have teams of people really trying to work on it gives them a fairly serious advantage over PHP in this respect.

share|improve this answer

1) Performance: several answers here are being mislead on that point.
The Phalanger project (which i used successfully in the past) allows you to use C# code within PHP and vice-versa, or to completely switch from one to the other language. You will probably have to make some changes, but as they keep working on it, it gets better and better.
My point is, they found out that there is an average factor of 2.5 speed in favor of C# (or .NET in general, VB would do the same, it's MSIL in the end).
Check out their tests with Wordpress, it attracted a lot of developpers.

Now we haven't seen him yet, but there's always the dude who's going to tell you that FaceBook is written in PHP. Wrong. It was, originally, until they realized their mistake, and wrote HipHop to transform it to C++.

EDIT: Apparently that last block is unclear, so what I meant is FaceBook IS written in PHP, but HipHop makes it RUN as C++, to improve overall speed, BECAUSE PHP is slow.

2) Security: As it has already been stated, PHP has a long history of security issues.

3) Developper time: Making a website in PHP tends to be easier, especially with the frameworks and all the "site-builders" available. Making a good, reliable and secure PHP website is another story.

share|improve this answer
    
As for the Facebook/HipHop thing, it doesn't change much. They still write PHP statements, don't they? There is also PHP to Java compiler. If I compile all my PHP code with it, does it mean my site is really written in Java? –  Jacek Prucia Mar 16 '12 at 15:42
    
It doesn't mean it IS Java, it means it executes as such. –  Baboon Mar 16 '12 at 15:45
    
Ok, you're right, but can I still claim that my site is written in PHP? If yes, then anybody can also claim Facebook is written in PHP. In other words, it all boils down to how you understand the term "programming language". Is it only the combination of valid statements or is it also runtime enviroment. I prefer the first meaning and that is why the HipHop thing doesn't change much for me. So pretty much i'm that FaceBook dude you mentioned :) –  Jacek Prucia Mar 16 '12 at 15:52
    
Alright, i'll make it clearer. But for the record, I'm pretty sure most of the readers understood my point. –  Baboon Mar 16 '12 at 15:56
    
It wasn't a mistake to write Facebook originally in PHP. When they found it couldn't keep up with the scalability they saw, they fixed the problem using HipHop. I guess this means using PHP is a very good option for all websites. That said, Slashdot uses straight perl and it'd solved the scale problem, wikipedia uses plain PHP and it too doesn't have scale problems. –  gbjbaanb Mar 17 '12 at 15:05

PHP is a fine option for enterprise solutions. Anyone who tells you differently doesn't know enough about PHP.

share|improve this answer
6  
Do you have any evidence to back this up? It's not that I don't necessarily disbelieve you, but... –  ChrisF Mar 16 '12 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.