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.
Originally Posted by ikeo
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.
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).
and let me know what you think
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.
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.
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.
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.
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.
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 =).
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.
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:
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?
void StartTimer(int ttl);
void StartTimer(time_t ttl);
void StartTimer(float ttl);
template<typename T> void StartTimer(T ttl); (assuming you're using a statically typed language that has actually at least implemented generics, of course...)
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.
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).
Have you actually worked with java web applications AT ALL?
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.
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'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.
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.
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).
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.
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]
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.
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.
as memory is so cheap
__autoload + auto_prepend_file directive can make it so that you never really have to worry about where your classes come from.
I'm not sure what you are talking about here, explain?
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.
PHP's arrays are not universally loved.
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.
Originally Posted by bonefry
And, again, something that doesn't matter to PHP because it's tearing down the app every view.
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
Or you can just do what everyone who knows anything about PHP does and use APC.
2) PHP, being so crapy, is recompiled at every request, so that Zend can make a living
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.
3) The cost of a new process is higher than the cost of a new thread
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.
4) The JAVA language can be optimized very efficiently because it is a static language
Lots of things don't exist by default.
5) A LAMP setup doesn't have stuff like connection-pooling by default
For those who say that PHP is more scalable that JAVA ... PHP is scalable because of its mediocrity
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.
... and tell me ... what infrastructure does PHP provide for distributed applications ?
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.
Anyone that says otherwise is clearly wrong, ignorant or religios about it.
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.
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 ;)
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.
In fact, PHP cannot scale too well precisely because of its shared-nothing architecture
Large development teams always lead to slow development. You break your project up into small, managable teams and put everything under source control.
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...
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.
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.
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.
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.
For some applications (we're discussing web apps, specifically here)
But just one question ... is Java and PHP comparable?
Not at all.
similerly is it fare to compare Zend Vs. SUN?
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.
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.
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.
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.
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.
Dynamically typed languages make such refactorings much more difficult.
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?
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.
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.
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.
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.
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!
Nobody's discussing money here. We're talking about startup cost in the performance sense. Again, read the whole thread.
WHAT STARTUP COSTS!
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.
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.
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.
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.