Could someone tell me why Java is faster than PHP

Actually, I think this is wrong. The two main issues that come to mind are that PHP lacks namespaces and that PHP is dymanically typed. The first I think most would agree with. With the second you can add comments to variables, methods etc to give hints about what they are suppose to be…but this is a bit hacky and usually developers get lazy with documentation. Also I’m aware of PHP5’s “type hinting” in methods, but this only solves a few of the problems.

Static typing is BAD if speed isn’t your #1 goal. And if it were, you would use C. Static typing can be good for languages like haskell, in which the compiler infers the types. In Java, it’s the human compiler at work.

Adding typing information to variable names makes things really ugly. Furthermore if you have to add typing information to the variable names and/or document how does this imply less work? You do the same work the difference is languages with static typing can use this information at compile time. Furthmore good IDEs in Java do all the typing work for you. Have you actually worked on a proejct with more than 50 files to manage?

You shouldn’t care too much about types. It’s come from old languages where speed was needed. The ide’s don’t do all the work, plus, it’s not only about writing and keystrokes, it’s also about reading. You’ll write code once, you’ll read it many times (if it’s not a throwaway program). Types in code you read = garbage => it slows you down.

I think it depends on what style works for you. A counter argument to this is that it may slow initial development time, but it may improve maintenance time. You only write your app once, but you may be refactoring/maintaining it for a long time to come. The argument could be made that you should optimize for maintenance and not for the initial development time.

What happens if you want to rename a class? Static typing is obviously bad for maintainance.

Prove that Java is “faster” than PHP in the general sense. “I think PHP is faster because of x” or “I think java is faster because of Y” doesn’t work. Make two applications that run similiar logic and test them by sending several hundred simultaneous requests at each. Come back and report the results.
:agree:

according to the complang shootout, Java is ~15 times faster than ruby, but uses ~5 times as much memory.

There was a presentation of ruby on rails. One rewrote his java app in ruby, and guess what? It was faster. With several caching metods, the speed advantage was 100-1000% (!). For highly dynamic websites, caching is no option. The speed advantage without caching was still 10-20%. The code was much shorter. The entire application in rails was about the same size as the xml configuration file of the java one.

You can still say that the Java version could have been made faster with caching. Example: you have 2 months to create an application. Because ruby code is much shorter, and faster to write, you have finished the ruby version in 3 weeks. You then have more than one month to set up caching :). You java app has cost you 1.9 months. No time to set up caching. In the end, the ruby one is faster. ;-).

What this means is that 1. the one who wrote the app was much better in ruby, even though this was his first ruby app. Or 2. he had to get around the limitations of the static java language, this made code huge, and slow.

I do not program so I am not qualified to write this. I’ll write my view on the matter from a non technical web surfers perspective.

Half the time php pages loud fast enough that I wouldn’t know its in php. I ALWAYS know if its JAVA because the damn thing takes a little while to loud the java applet. After the applet is louded it works fine and is fast though. But I hate waiting for the damn thing to load in the first place. I want the information now, not in 10 seconds. Java also seems to use more of my system resources that a php application does… I don’t always like that. Sometimes I might have 15 windows open including a few programs, lots of web sites, a music program, and some of those damn pdf files. Then you get another page that is java based… just what I needed, more resource drain.

But what do I know? I’m just the non-technical end user.

Hmm that makes no sense. And the parser wasnt for a web application.

Well the site clearly states why php should have namespaces…but they don’t offer a solution they offer ideas on how a solution would look like. I mean they clearly state what they are doing is for demonstration. Namespaces are the sorts of things that need to be added to the language itself.

Yes, due to the open source nature the differing patches get evaluated for inclusion into PHP language.

:nono: The only thing that is obvious is that you have no experience with modern statically-typed languages, and are speaking from ignorance. Static typing makes renaming classes, methods, constants, etc. easier because tools such as IDEs can perform static analysis on your code and know 100% that all references have been updated. Try a modern IDE such as Eclipse. It has refactoring tools built-in that do things like renaming classes, methods, variables, packages, etc. In Eclipse you select an identifier, hit ALT-R, type in the new name, and you are done. ALL references in your project are updated automatically. No regular expression search and replaces required. And this is possible precisely because of the information that static typing provides the tool.

Dynamically typed languages make such refactorings much more difficult. Sure, you can use regex search-and-replaces (I do it all the time with my PHP code in jEdit) but you cannot be gauranteed that all references were updated. (I know, I know, that’s what unit testing is for.) Tools cannot automatically handle this for you because it’s impossible to know where all the references to the code you want to refactor are without actually running the application and hitting all conditionals/branches/etc. Since PHP (and other dynamic languages) allows you to store the names of classes, methods, etc. as strings and invoke them that way even the most inclusive regex can’t gaurantee that all references are updated.

Besides simple renames, Eclipse (and other Java IDE’s) provide support for other refactorings including “extract method”, “inline method”, “extract interface”, etc. Simply put, if you have never used a modern IDE with a statically typed language such as C# or Java then you have no idea what static typing makes possible regarding tool support. There is simply no analog to this in the PHP world.

I think the CLR does have a JIT compiler. I also recall that sun’s hotspot compiler was created as a reaction to JIT compilation in the Microsoft Java product (the precursor to CLR). That was back when they were going back and forth over Java. I could be remembering wrong.

  1. PHP, being so crapy, is recompiled at every request, so that Zend can make a living

I really hope APC will be standard in PHP 6. There is no reason for it not to be. PHP standard should have at least an opcode cache. Leave the opcode optimization to commercial Zend. Perhaps having a standard opcode cache would force Zend to include JIT capability in their commercial product to take it to the next level?

  1. The cost of a new process is higher than the cost of a new thread

Normally, one would tune an apache configuration to have a certain number of processes on hand to avoid creating new ones all the time.

No, there is a nearly complete working patch available at that site. I was lurking on the Propel users list when the people that created that site were talking about it. The problem is the PHP devs were not terribly interested in looking at it. They have stated (finally) that they are planning on adding namespace support to the language in PHP 6 but they have decided not to use that patch and are starting over from scratch (which means, don’t hold your breath).

I mean they clearly state what they are doing is for demonstration.
This disclaimer was added after Zend (or should I say, “The PHP Group”) took issue with their use of the name “phpnamespaces.org”. Zend felt that they were violating the PHP license by offering an effective “fork” of PHP with namespace support compiled in. That’s when those in control of phpnamespaces.org added the disclaimer. The patch there is, by all accounts, quite stable and reliable (I have not used it myself… I don’t like having to manually track changes and patches and prefer to stick with the official PHP distribution for maintenance reasons). Unfortunately it has not been accepted into the core and most likely will never be.

Oh JOY, arguements about what languages is the best never really get anywhere.

Paul Graham talks a lot about language, and of course he will side towards Lisp, but here is an interesting piece about Java.

http://www.paulgraham.com/javacover.html

This whole thing reminds me of the Mythbusters episode where they put the toy car against the real car. Over 100 feet the toy car was faster, but over 400 feet it was slower. It really comes down to the specifics of what you are measuring to determine if one is faster then the other.

I agree with you on the boring language debates (and on the Mythbusters allusion- that was an interesting episode), but that link doesn’t really add anything to the discussion:

That’s like saying “I’ve never been to Russia, I don’t know anything about the culture or history of Russia, but I think it’s a crappy country”. In terms of making an argument, I personally think that falls short. Not to mention that he wrote it in 2001, and Java has come a long way since then.

Oh HOW have I missed this one for so long.

OK, Most people who know me are thinking “Here comes the fire and brimstone Java zealot” … sorry that was then.

Anyway, here some specific answers to somethings that made me twitchy:

I’m sorry but that has go to be one of the most uniformed things I have ever seen posted anywhere! Where oh WHERE do you come up with that and what proof do you have.

Why is it some of the largest enterprise web applications are written in Java? Power and Scalabilty! Look at Ebay, UPS, Fedex, PetsMart (I could go on for ever) … I have yet to see an honest to god enterprise level application written in PHP … PLEASE show me one!

I know this has been answered but I had to add my 2 cents. High memory usage in Java apps almost always point to lousy coding! There are some things I’ve worked with (like the Java image API) that do tend to use some serious memory but nothing more than wouldn’t be expected loading massive images into memory for manipulation.

I monitor my servers constantly (all Java enabled) and see NO extra memory use when the “big” apps are running … again, high memory use in java = bad programming!

OK, now you really need to explain these “high start up costs”!!! WHAT STARTUP COSTS! The j2sdk is FREE, things like Apache’s Tomcat (although not my fav) FREE … 99% of the 3rd party APIs … FREE, so what freakin costs are you talking about! And don’t even give me that J2EE package from Sun… NO self respecting Java developer would pay for that when you get the exact same thing in a servlet engine like Resin!

Just total horse hockey!

You are talking about something that is less than 1% of the use of Java … Applets??? Oh for crying out loud … talk about 1990s!

I could give you a list of sites and apps I’ve written in Java that you would NEVER be able to tell the were java powered and they are ALL SMOKING FAST!

Anyways … I’m NOT a “java for everything nut”, I also use PHP for simple websites and apps, also for those clients who dont have Java enabled servers. PHP is fine for this type stuff, it’s easy to write (usually) and works fast enough. BUT when I need a massive app that has to be able to do anything I need in any way shape or form I go to Java.

As far as faster? Without some really stupid tests I don’t think anyone can prove it either way and honestly WHO CARES!

I’ve seen painfully slow apps in Java, PHP, ASP, Perl and .NET and you know what I find 99% of the time is the problem? LOUSY PROGRAMMERS who dont learn all the ins and outs of their language … they buy a book, hack together some code and call themselves a programmer!

Most of these painfully slow apps all have one thing in common (besides lousy programming that is) … they are running over a database and the programmer has NO CLUE how to effectively use that db! I’ve seen queries that would choke the most powerful servers in the world. I’ve seen loops that made call after call to dbs when in fact if the programmer knew what they were doing they could grab all the data in a view with one call AND let the database servers do what THEY do best, manage and serve DATA.

I’m actually looking at one of these hack apps right now as a matter of fact, freaking Tomcat 5, Hibernate, Struts and a Firebird database… my god this thing makes me want to cry it’s so slow … another hacked together app by ANOTHER hack “programmer” who thought it was all so cool. I’ve told this company there is no way in hell I’ll even try to fix this piece of crap … it’s a total rewrite!

So before any of you start with this “my language is faster than yours” just because you see a slow web app take a look at what ELSE could be wrong… 9 times out of 10 it probably has NOTHING to do with the programming language at all!

Whoever argues in this topic about either language, is not a successful developer, I’ll tell you that.

Only ColdFusion developers would say something like THAT in an attempt to make up for their language’s own shortcomings. Just kidding. :slight_smile:

People need to chill. Different strokes for different folks, and all that jazz.

You shouldn’t care too much about types.

I care about static typing…for many reasons that have already been stated.

What happens if you want to rename a class? Static typing is obviously bad for maintainance.

What happens is you click the “refactor” button and click “rename” and the IDE you are using renames all instances of that class in your project to the new name. Dymanically typed languages don’t avoid this issue…

No, there is a nearly complete working patch available at that site.

“Nearly complete” in other words its not complete and can’t be used in product code. PHP still lacks namespaces.

There was a presentation of ruby on rails. One rewrote his java app in ruby, and guess what? It was faster.

These sorts of things are meaningless. Was the java implementation done well? etc. Also do you have a reference to this result? If not…why bother?

really hope APC will be standard in PHP 6. There is no reason for it not to be.

There is one reason it should not be…Zend wants to make Money off its stupid “Zend Platform”. This is one reason I dont’ use PHP much…to get nice features (that are stable) you have to get the Zend Platform. Where as other technologies (servlets, mod_perl, mod_python) etc you get it all for $0.

> There was a presentation of ruby on rails. One rewrote his java app in ruby, and guess what? It was
> faster.

I don’t believe that for one minute. It’s doubtful at best, considering the current release version of Ruby On Rails at the moment, and the numerous issues such as performance on speed for one.

Besides, to compare one platform against another is rudimentory at best, since there are just too many variables to take into consideration between those platforms.

Sure, just run a test that loops through infinitely and allocate / free memory (drop refcounts using null assignment), and notice how memory doesn’t get freed very quickly. There are also many memory leaks that create all sorts of problems. In a web app, it really doesn’t matter (the context only lives for a fraction of a second), but in a daemon it’s a killer. This is a known limitation of the PHP engine, and it’s not likely something that’s going to be fixed anytime in the near term.

I’ve done some reading on this, and from what I understand JIT would help Java perform better than PHP because PHP is interpreted (after being compiled to Zend opcode).

read this and let me know what you think
Like I said, in theory a JRE should be able to run faster, but in practice it doesn’t. The main reason is because of all the extra overhead that the JRE has to carry around with it throughout the process.

What the hell are you even talking about? In java any code that becomes “hot” will be compiled to native code. Whether that code is running a web application or desktop app simply doesn’t matter.

Because the time required to compile to native code is unacceptable in the context of a web app. JIT is nice in theory, but in practice it never lives up to it’s expectations. That’s why we’re seeing emergence of things like compile on install, like what you get with .Net.

google.com - Anybody that denies that Java as a language is faster than PHP is a mindless fan-boy of PHP. …hell try writing any NON-TRIVIAL algorithm in PHP and Java and see which which does better. PHP can solve some of its performance problems by outsourcing its work to C via an extension though. PHP is just not in the same class as Java, compare it to Perl, Python etc.

Google uses Java for some of their apps (and python, and perl, and, from what i’ve been told, even some PHP), but their search engine is most certainly not built in Java. Yahoo, however (which gets much more traffic than google on a daily basis) is mostly built on PHP (although extensions are used…extensively). Yes, on a straight algorithm vs. algorithm basis, Java will beat PHP in most circumstances – but anybody who’s actually developed a real application knows that you can’t use that as a basis for comparison.

Sure they have advantages…one of the advantages NOT being scalability. And…hmm…call me crazy but I’d imagine that a variables Data type would indicate something namely its data-type =).
If you don’t think PHP applications are scalable, you’re just plain wrong. Wikipedia, yahoo, flickr, etc. – all built with PHP. I work with large scale, high performance, extremely high scalability systems every day, and scripting languages have a huge advantage here due to the fact that you can always just toss more instances at the problem. It works every time. PHP just happens to be better than most because it runs faster than the other popular scripting languages.

Again, what does data type tell me about an object? Absolutely nothing. In fact, it can be a hindrance because now when I want to change my data type later, I’m stuck having to manually go through my code to adjust.

Statically typed languages have to resort to nasty hacks like generics to solve the problem.

Adding typing information to variable names makes things really ugly. Furthermore if you have to add typing information to the variable names and/or document how does this imply less work?
I never said “add typing information”. I said “use sensible variable names”. That means names like “PlayerName” or “NumberOfIterations” or “TimeToLive”. You could do something like this in a statically typed language:

void StartTimer(int ttl);
void StartTimer(time_t ttl);
void StartTimer(float ttl);

or, perhaps:

template<typename T> void StartTimer(T ttl); (assuming you’re using a statically typed language that has actually at least implemented generics, of course…)

etc.

In php, you’d never have to change that function signature.

If you have a case where you REALLY think that the type of data requested is going to be non-obvious (and you can’t be bothered to add comments to the function signature), PHP supports type hinting:

function CompareTwoObjs(MyObj $Obj1, MyObj $Obj2);

as well as various functions for comparing data types.

Again, no FORCING of static typing on anybody.

Have you actually worked with java web applications AT ALL?
Yes. And I don’t deal with apps that just run on one server. The apps I write are built to be cross colo, multi-server applications designed to handle millions of unique visitors every month. I can say with absolute certainty that what we do where I work gets more traffic than what you do where you work. You CAN’T just scale a java app by throwing more hardware at it, but time and time again it’s been shown that you can do that with many PHP apps (not all, of course, since database dependencies and such can bite you, but there are plenty that do just that).

Large web applications have thousands and thousands of source files being worked on by many people…there is no sensible way to manage this with PHP.
You don’t manage source with PHP, you manage it with CVS (or SVN or Perforce, if you prefer). I can assure you that the thousands of PHP source files that the company I work for has in our CVS repository work just fine for us.

don’t see how a platform that has “pretty terrible” garbage collection can possibly excel as a general-purpose scripting language. “General-purpose” means that you may not be dealing with short-lived requests and environments that are being tossed out rapidly.

You’re confusing general purpose language with general purpose SCRIPTING language. Java, C, and C++ are general purpose languages. When I say scripts I’m talking about scripts in the literal sense – bits of code that perform simple, quick tasks, then exit. PHP serves as a fine replacement for Perl or Bash in almost all cases.

My personal opinion is that the lack of namespaces in PHP makes encapsulation at a library-level difficult and discourages the development and sharing of generic classes and class libraries.
Yes, PHP’s lack of namespaces is annoying, but it’s hardly as crippling as some people make it sound. C (NOT C++!) doesn’t support namespaces either, but it’s used by thousands of developers around the world on thousands of projects (and is much older than any of the languages being discussed).

[offtopic]

Actually, I’ve seen it stated that Ruby scripts are currently not compiled to bytecode/machine language, but are converted into an abstract syntax tree and interpreted. So, it could be argued that Ruby isn’t compiled.
a rose by any other name…The compilation method differs from others, but it’s still a case of converting a language into a simplified representation and then passing it into a machine that can interpret those commands (directly to the processor, into a VM, etc.) [/offtopic]

as memory is so cheap
Memory is only “cheap” under a few circumstances. If you’re dealing with sunfires or such, then adding more ram is generally not a big deal, but that type of hardware is so overpriced as a whole that it really doesn’t make the RAM “cheap”. To achieve the high levels of scalability demanded by many of today’s web sites (e.g. google, yahoo, etc.), you’re dealing with a commodity hardware paradigm. 2GB or 4GB of RAM is fairly cheap, but most of these machines are limited to 4 or 8 memory banks, and RAM is exponetially more expensive the larger your modules are. There’s very little sense in putting 16GB of RAM into a box like this when that extra 12GB cost you twice as much as it would to add another server. That’s why they don’t do it.

I’m not sure what you are talking about here, explain?

__autoload + auto_prepend_file directive can make it so that you never really have to worry about where your classes come from.

PHP’s arrays are not universally loved.
The only real case where they cause problems tends to be when you need to do array merges, though. PHP’s other conventions make it so that it’s an ideal system. For most stuff that you’d use PHP for, maps make much more sense than arrays. I wouldn’t be opposed to seeing a purely indexed array added, but I’d also be willing to bet that it’d get very, very little use.

Oh, Java does use a lot of memory on mobile applications. That’s why writing mobile apps is such a pain in the butt. The ONLY reason for Java’s success on mobile devices is because writing portable C code for what is literally thousands of different architectures would be nearly impossible.

JAVA beats the living crap out of PHP, when it comes to performance, for the following reasons:

  1. The Hotspot JVM knows about “adaptive optimizations” … something that even the .NET CLR doesn’t have yet

And, again, something that doesn’t matter to PHP because it’s tearing down the app every view.

  1. PHP, being so crapy, is recompiled at every request, so that Zend can make a living
    Or you can just do what everyone who knows anything about PHP does and use APC.
  1. The cost of a new process is higher than the cost of a new thread
    Not by much on linux or freeBSD, and the overhead of locking usually far outweighs the overhead of extra processes. Threading is usually only advantageous when you need to do a lot of inter-process communication on these systems. Aside from that, PHP IS thread safe (at least in all the core libraries, some extensions aren’t), and works perfectly fine with apache’s MPMs.
  1. The JAVA language can be optimized very efficiently because it is a static language
    In theory, yes, in practice it makes very little difference for the types of applications you’d use PHP for. Yes, Java would trounce PHP-GTK for desktop development, and Java would smoke PHP for long-lived server processes, but otherwise it makes little to no difference.
  1. A LAMP setup doesn’t have stuff like connection-pooling by default
    Lots of things don’t exist by default.

For those who say that PHP is more scalable that JAVA … PHP is scalable because of its mediocrity
Uhm…right.

… and tell me … what infrastructure does PHP provide for distributed applications ?
Are you talking about distributed as in load balancing or distributed as in package distribution? For the former, it doesn’t need it, and for the latter you’ve got PEAR, PECL, or, well, any package management utility, since PHP doesn’t require any kind of application registration or other such nonsense. You copy files to where they need to go and you’re done.

Anyone that says otherwise is clearly wrong, ignorant or religios about it.
Except for when they’re right. Web sites using PHP (big ones like Yahoo and Wikipedia) continually demonstrate lower hardware costs than Java based ones (Amazon being the nearest compatable site in terms of size off the top of my head). If Java is superior in performance, then why doesn’t that show up in practice? You could possibly argue that Yahoo and Wikipedia have far better engineers than Amazon, but I’m pretty familiar with people working at these organizations and I can assure you that it isn’t the case.

This thread is useless as it clearly leads to a flamewar … because of fan-boys that can’t accept the limitations of a scripting language … and thus they bash a technology they do not use or know.
If you want productivity, then PHP may be the answer for you, but if you want performance … with PHP it is like looking against the SUN :wink:

How about the fan-boys that can’t accept the fact that a scripting language can trounce a compiled language, even when the evidence is right there in front of them? No, in the “general sense” PHP isn’t faster than Java, but for the things you use PHP for, it is.

In fact, PHP cannot scale too well precisely because of its shared-nothing architecture
You’ve got that completely backwards, friend. If you actually want to explain why you don’t believe this to be true, go ahead, but anybody who’s actually dealt with situations where hundreds of requests per second are being thrown at an app can tell you that the “shared nothing” architecture works like a dream.

Why wouldn’t they? Part of what makes a application scalable is its ability to deal with large development teams, large code bases etc. Which language used clearly effects this…
Large development teams always lead to slow development. You break your project up into small, managable teams and put everything under source control.

Your point is just myopic. Please look at what it takes to implement a regular expression engine (and regular expressions are used ALLLL over the place in web apps). When you start writing non-trivial web applications you’ll find that there are no longer PHP extensions to do all the hard work for you.
I write plenty of “non-trivial” web applications, and, while there are certainly some things that PHP doesn’t do well, It’s pretty rare to encounter a situation where there isn’t already an extension to do the hard work for you. The only cases where I can recall in recent memory where there weren’t good solutions in PHP was when I had to interface with external services that were being provided through some low level system (shared memory transports and the like). Most people on this forum will NEVER have to deal with these types of issues.

Well the site clearly states why php should have namespaces…but they don’t offer a solution they offer ideas on how a solution would look like. I mean they clearly state what they are doing is for demonstration. Namespaces are the sorts of things that need to be added to the language itself.

Actually, they do offer a solution (and it works), it just hasn’t been made a part of PHP yet due to some performance issues that are still being sorted out. Most likely no decision will be finalized until PHP6 and all the unicode changes have been finalized.

But just one question … is Java and PHP comparable?

For some applications (we’re discussing web apps, specifically here)

similerly is it fare to compare Zend Vs. SUN?

Not at all.

The only thing that is obvious is that you have no experience with modern statically-typed languages, and are speaking from ignorance. Static typing makes renaming classes, methods, constants, etc. easier because tools such as IDEs can perform static analysis on your code and know 100% that all references have been updated.

Except that you rarely, if ever, control all the code that you’re working with. It’s the old “binary compatability” problem. I’d love it if there was an IDE capable of actually loading 1000+ files at once and doing find and replace on them all.

In Eclipse you select an identifier, hit ALT-R, type in the new name, and you are done. ALL references in your project are updated automatically. No regular expression search and replaces required. And this is possible precisely because of the information that static typing provides the tool.

Actually, this tool does use regexes to update. It just changes the source code. Just because you don’t have to manually type in a regex doesn’t mean that’s not what’s happening.

Dynamically typed languages make such refactorings much more difficult.
They would, if it weren’t for the fact that you don’t need to do it in the first place because you don’t declare type.

Since PHP (and other dynamic languages) allows you to store the names of classes, methods, etc. as strings and invoke them that way even the most inclusive regex can’t gaurantee that all references are updated.
Nope, and in Java you can’t do that AT ALL (well, you kind of can with reflection, but that has the same limitations that you just mentioned). What’s your point?

Simply put, if you have never used a modern IDE with a statically typed language such as C# or Java then you have no idea what static typing makes possible regarding tool support.
Because you DON’T NEED IT in PHP. The most useful tool that most IDEs provide is autocomplete (intellisense, if you will) and module / function / class heirarchy management. Both eclipse and zend studio do this just fine for PHP.

Why is it some of the largest enterprise web applications are written in Java? Power and Scalabilty! Look at Ebay, UPS, Fedex, PetsMart (I could go on for ever) … I have yet to see an honest to god enterprise level application written in PHP … PLEASE show me one!
Wikipedia, Yahoo, etc…all mentioned already (and lets not even get into all the usage of C/C++, perl, and python). Maybe you should have read the whole thread before you commented. Java got sold to enterprise customers because Sun marketing people pushed it at the same time that they were pushing hardware, so it caught on.

WHAT STARTUP COSTS!
Nobody’s discussing money here. We’re talking about startup cost in the performance sense. Again, read the whole thread.

PHP is fine for this type stuff, it’s easy to write (usually) and works fast enough. BUT when I need a massive app that has to be able to do anything I need in any way shape or form I go to Java.
And this ENTIRE THREAD has been about web apps. Nobody’s trying to argue that PHP is faster than Java in the traditional application space. I’d also question the wisdom of ever creating a “massive app”, in any language, on any platform, for any purpose.

There is one reason it should not be…Zend wants to make Money off its stupid “Zend Platform”. This is one reason I dont’ use PHP much…to get nice features (that are stable) you have to get the Zend Platform.
Funny, I’ve never used Zend’s products outside of the evaluation period (some of their tools are alright, most of them aren’t really worth the money in my opinion), and I can’t think of a single “nice feature” that they have that I don’t currently have in a stable form.

No, as I stated, rename refactoring is accomplished via static-analysis of the soure code. The static-typing information makes it possible to know for certain at compile time the types of each variable, and where each type and method are referenced. In Eclipse, regular expressions are only used if you choose the option to “Update textual matches in comments and strings” or to “Update fully qualified name in non-Java files”. In fact, because these things are inexact, the refactoring tool forces you to preview the changes before they are made. But changes to the actual code are not updated via regexes. If you have reason to believe they are, please back up your assertion.

Holy crap Etnu! You can’t be human!
I am so glad to be seating at the feet of obviously smarter more experienced developers … who don’t even know I’m there :]

I had a few questions about some things you’ve posted.

You said PHP uses Reference counting, I looked over it briefly in Wikipedia and it is supposed to be faster in theory since once an object is no longer referenced it is reclaimed .... Is it that Zend just does a bad implementation of it in their garbage collector for PHP?

- In regards to static vs Dynamically typed languages I think this amounts to a Holy war. It is clear that both have their benefits, I think in a web environment dynamic typing wins out? I've been doing a lot of code in ASP.NET (C#) and being forced to declare type just seems like a hassle with no true reward for my trouble.

Question to Etnu: Don't you think PHP would benefit from being able to switch between being able to check types and the old fashioned way of just making a best-guess conversion? Just something like an application variable you could turn on or off.

You don’t manage source with PHP, you manage it with CVS (or SVN or Perforce, if you prefer). I can assure you that the thousands of PHP source files that the company I work for has in our CVS repository work just fine for us.
I’m interested to see what Snailly will say on this.

Yes, PHP’s lack of namespaces is annoying, but it’s hardly as crippling as some people make it sound. C (NOT C++!) doesn’t support namespaces either, but it’s used by thousands of developers around the world on thousands of projects (and is much older than any of the languages being discussed).
Great point … I hadn’t thought about that.

Not by much on linux or freeBSD, and the overhead of locking usually far outweighs the overhead of extra processes. Threading is usually only advantageous when you need to do a lot of inter-process communication on these systems. Aside from that, PHP IS thread safe (at least in all the core libraries, some extensions aren’t), and works perfectly fine with apache’s MPMs.
This contrasts with what Jonas Maurus says here …

PHP isn’t thread-safe
PHP 4 and 5 can only be used with Apache2’s mpm_prefork model, not with mpm_worker. That means that PHP limits your performance choices with the Apache HTTP-server. It seems that it can be used with mpm_worker by not using the mod_php plug-in directly, but by using FastCGI.

How say you?

How about the fan-boys that can't accept the fact that a scripting language can trounce a compiled language, even when the evidence is right there in front of them? No, in the "general sense" PHP isn't faster than Java, but for the things you use PHP for, it is. 

Just from the back and forth on this thread and anecdotal evidence from surfing Yahoo, Flicker, Sun, ebay et al. I think their speed is just about even, which of course (for the pro-PHPsters) sounds like a win for PHP, since Java is (theoretically) supposed to wipe the floor with it.

You’ve got that completely backwards, friend. If you actually want to explain why you don’t believe this to be true, go ahead, but anybody who’s actually dealt with situations where hundreds of requests per second are being thrown at an app can tell you that the “shared nothing” architecture works like a dream.
I’d honestly like to see a bit more detail from both sides about this. I understand PHPs “shared nothing” architecture but I don’t see why it would help it scale or not (forgive me if I sound naive … around here I am)

That was a lousy read. It was dated, the guy didn’t know anything about Java and it showed.

The garbage collector is crap. But it doesn’t really matter, and nobody cares unless they’re trying to write daemon processes in PHP for the most part, because when the process is finished, everything is “garbage collected”. Yes, refcounting is fast, but it’s also error prone (see the microsoft DOM implementation for IE…). Regardless of the GC methodology being used, nothing is effective if your GC is crap the whole way through.

- In regards to static vs Dynamically typed languages I think this amounts to a Holy war. It is clear that both have their benefits, I think in a web environment dynamic typing wins out? I've been doing a lot of code in ASP.NET (C#) and being forced to declare type just seems like a hassle with no true reward for my trouble.

Static typing is important for micro-optimization and situations where expected data types can be ambiguous. PHP solves the latter problem by way of type hinting.

Question to Etnu: Don't you think PHP would benefit from being able to switch between being able to check types and the old fashioned way of just making a best-guess conversion? Just something like an application variable you could turn on or off.

It does and can. It’s called type hinting.

This contrasts with what Jonas Maurus says here …

How say you?

PHP is thread safe, some extensions are not. Look up ZTSRM (Zend Thread-Safe Resource Manager) for more details. Most experienced people will tell you that on a linux or bsd box, though, you’re better off spawning more processes instead of threads for this sort of task.

I’d honestly like to see a bit more detail from both sides about this. I understand PHPs “shared nothing” architecture but I don’t see why it would help it scale or not (forgive me if I sound naive … around here I am)

Simple, if the process doesn’t have to share anything, and it’s all torn down between requests, then you have a situation where scalability is simply a matter of having more processes available to handle requests. No worries about communication between systems of any sort. In other words, it’s a whole lot easier to spread the load across multiple machines. Now, obviously this is a huge oversimplification (you’ll ALWAYS have other bottlenecks in any app), but it does ensure that PHP will rarely (if ever) be your bottleneck. This approach would never work for most traditional applications, but it works perfectly for the web.

I hate to bring it up again, but it has to be said: Friendster.

Not wanting to go off topic, nor am I looking for an arguement, but…

> In fact, it can be a hindrance because now when I want to change my data type later, I’m stuck
> having to manually go through my code to adjust.

You would not have to do that in the event you are using PHP5? If you are using PHP5 you should be developing with Interfaces in my view; While not entirely removing the problem, you would find that you have more scope and options if you were to use Interfaces.

If you are using Interfaces, and you still are having trouble, then I can only imagine that either you are not using Interfaces properly, or that your not taking the full advantage of what Interfaces offer the developer :slight_smile:

Good post btw…

Oh god…

Well, Etnu, let me help you a bit, yeah?

Like I said, in theory a JRE should be able to run faster, but in practice it doesn’t. The main reason is because of all the extra overhead that the JRE has to carry around with it throughout the process.

There’s no such overhead. The JRE only loads what it needs…

Because the time required to compile to native code is unacceptable in the context of a web app. JIT is nice in theory, but in practice it never lives up to it’s expectations. That’s why we’re seeing emergence of things like compile on install, like what you get with .Net.

That’s wrong. The Java-files will be compiled once. Actually, you’re not going to upload *.java files to a web-server… you’ll upload an JAR/EAR with *.class files. These will be loaded by the server when they’re used. They’ll get JIT-compiled into processor-optimized native code (much better than C could do). Once HotSpot got hold of them, you’ll have them and there’s no need to recompile it. PHP interprets the Opcode every time. It doesn’t get optimized and it won’t become native code. It’ll do that for every request. Are you seriously trying to tell us an interpreter written in C could be faster than native code, optimized for the particular processor your code is running on? Have you even thought about that?

Again, what does data type tell me about an object? Absolutely nothing. In fact, it can be a hindrance because now when I want to change my data type later, I’m stuck having to manually go through my code to adjust.

The data type tells me a lot about the object. It tell’s me what kind of an object it is. It tells me what I can expect the object to be able to do, it tell’s me what the object knows. Actually, it tells me everything I need to know about that little object.
I won’t want to change the data type later on. Why would I want to do that? Appears to be really stupid to me.
In the code working with the object you’ll have method-calls on this object, you’ll access properties, you’ll pass it to other methods that themself rely on the type of that object. Are you sure you know what an object is?

Statically typed languages have to resort to nasty hacks like generics to solve the problem.

Generics solve an entirely different problem… that is, for example, for object (like collections) that do not care about the type of object they’re collection. For that, generics provide compile-time safety. Generics are an add-on to provide static typing to collections and the like!

I never said “add typing information”. I said “use sensible variable names”. That means names like “PlayerName” or “NumberOfIterations” or “TimeToLive”. You could do something like this in a statically typed language:

What type is “PlayerName” of? Is it a type itself? Could very well be, maybe a subclass of Name. Or did you mean it to be a String? Couldn’t tell from that name, though…

What is “NumberOfIteration”? A number? What do you mean by “number”? A double? An int? Maybe a byte? Or is an object itself?

I’m, however, pretty sure your “TimeToLive” would be a variable of type “Time” - except it is an unix-timestamp… in that case it’d be an int/long… oh well… guess I do not know what type it is of… I’m sorry.

In php, you’d never have to change that function signature.

But if you have to (because of maintainance), it’ll break your neck. With modern Java-IDEs this is one of the easiest tasks. With PHP, your toast (I’m working on this, though - but because of missing types in PHP my work on producing a real IDE for it is way harder - if I had decided to create a Java-IDE I’d be done by now…).

PHP supports type hinting:

I’m using this in every PHP-project I’m working on. I’m really glad they added this. Now, if they had only added type hinting for the return value and general variable types - I’d be happiest man ever.

The apps I write are built to be cross colo, multi-server applications designed to handle millions of unique visitors every month. I can say with absolute certainty that what we do where I work gets more traffic than what you do where you work. You CAN’T just scale a java app by throwing more hardware at it, but time and time again it’s been shown that you can do that with many PHP apps (not all, of course, since database dependencies and such can bite you, but there are plenty that do just that).

There are a lot of Java-apps out there that handle multiple millions of visits per day.

You don’t manage source with PHP, you manage it with CVS (or SVN or Perforce, if you prefer). I can assure you that the thousands of PHP source files that the company I work for has in our CVS repository work just fine for us.

Reread what you’ve answered this too… it’s almost off-topic.

Yes, PHP’s lack of namespaces is annoying, but it’s hardly as crippling as some people make it sound.

It isn’t? Really? Well… if you new how angry I was when PHP added SPL, you wouldn’t say that. It is because of the lack of namespaces that one has to fight with stupid classnames like “PEAR_Whattheheck”. Or, otherwise, having to fear that one day your code will break because you’ve been using classnames that PHP now uses for its own purpose. This breaks code and that is a serious issue.

And, again, something that doesn’t matter to PHP because it’s tearing down the app every view.

And doesn’t get the benefit of native compiled code, yepp. You might want to change your statement to: You can’t bring that as an argument. PHP doesn’t even get half the way where it would be worth to think about this stuff. Another answer of yours could be: Sorry, I don’t know what I’m talking about.

Or you can just do what everyone who knows anything about PHP does and use APC.

And let the Opcode be interpreted, instead of using native code once HotSpot detected it with Java.

Except that you rarely, if ever, control all the code that you’re working with. It’s the old “binary compatability” problem. I’d love it if there was an IDE capable of actually loading 1000+ files at once and doing find and replace on them all.

They do… actually. Ok, they’re processing them one after the other for this kind of task, but they’ll go through all of your projects code and change it to represent the changes.
This is also how my own IDE will do this, too. It’ll open all project files and try to apply the changes. Due to the nature of PHP this will be a really hard task as there are nearly no information about the types, but…

Actually, this tool does use regexes to update. It just changes the source code. Just because you don’t have to manually type in a regex doesn’t mean that’s not what’s happening.

These tools use a real parser to build an AST of your sources. It’ll then operate on this AST.
More advanced Java-IDEs like IntelliJ IDEA even provide search-and-replace functionality based on an AST as well. You type a statement to be looked for, it’ll be compiled to an AST and then it’ll be searched for in the sources.

They would, if it weren’t for the fact that you don’t need to do it in the first place because you don’t declare type.

Oh yeah… you don’t use the “new” statement, don’t you? And you’ve never renamed a method, right? And of course it wouldn’t even come to your mind to change an object to a singleton. Modern IDE do all this for you with just a few refactorings…

Because you DON’T NEED IT in PHP. The most useful tool that most IDEs provide is autocomplete (intellisense, if you will) and module / function / class heirarchy management. Both eclipse and zend studio do this just fine for PHP.

Yeah… if you say that, you must be right. And I should stop my development right now. PHP-developers don’t need an IDE that makes them productive. They never look back at their code once they wrote it and if it is necessary at all, they’ll just start from scratch… oh boy… grow up, please.
There are features in Java IDEs you don’t even dream about if you’re pleased with Zend Studio.

Wikipedia, Yahoo, etc…all mentioned already (and lets not even get into all the usage of C/C++, perl, and python). Maybe you should have read the whole thread before you commented. Java got sold to enterprise customers because Sun marketing people pushed it at the same time that they were pushing hardware, so it caught on.

I don’t know about Yahoo, but Wikipedia certanly isn’t a good example for a big website. Sure, it contains quite a few things in its database, but compared to eBay that’s just a joke. Building a Wiki is something everyone with a year of coding experience could do easily. Take data from database, print it, be done. Really a complex application…

Nobody’s discussing money here. We’re talking about startup cost in the performance sense. Again, read the whole thread.

The startup cost of a running server isn’t really high… also, as far as I know, servers like Resin and Tomcat take around 30 to 40 seconds to restart… and they stay running.
If you want to talk about startup cost, you’d want to discuss desktop-applications, not servers (also, this is mostly a discussion of Tomcat vs. Apache).

Just to clearify this: I use PHP myself very often (not as often as I did a few years ago, though). I use it to build small cms and shops for sites with little traffic. I’m using Java for desktop applications.
I like both, PHP and Java, but I prefer Java. Mostly because of the weak IDEs for PHP.