58 Comments
- unidentified, on 10/12/2007, -5/+41Yeah, then I can have the mighty Java Runtime Environment start up and eat 50megs of my memory to speed up your 1mb program by 5%.
Here comes the java mod control in 3... 2... 1... - shakin, on 10/12/2007, -1/+17Absolutely. Java is inherently faster than PHP at serving web pages.
Oh wait, no it's not. In fact, the raw speed difference between PHP and Java is almost meaningless considering code execution is almost never the bottleneck for a web site. Nine times out of ten the database is the bottleneck and you can use either PHP or Java to cache results, pool connections, etc (that is, when your table is already properly indexed).
The meaningful differences between PHP and Java are development time, scalability, execution environment, libraries, and deployment management. Sometimes PHP is better and sometimes Java is better, depending on your needs.
FWIW, the slowest web site I've ever seen (pre-caching) was Java-based and the second slowest (pre-caching) was PHP-based. After caching content both were lightning-quick. - gharding, on 10/12/2007, -1/+9It was a joke.
But here:
http://www.timestretch.com/FractalBenchmark.html
And seriously, Java is backed by some of the largest corporations in the computer industry. Sun, Oracle, Redhat, IBM. Java is also one of the largest focuses of the Apache Group, as well as many other open-source communities. Each of these companies has released a ton of SOLID Java frameworks and utilities (many of which I use every day).
As for scalability, PHP has no support for persistence. Threading in PHP is pretty much a joke, too (and it doesn't even work in Windows).
Java is relied upon by most of the large financial corporations in this world (and I've worked with a bunch of em!). (Is there even a FIX implementation for PHP?) And has anyone implemented their middleware in PHP? If they did, they probably don't have a job anymore!!
I think it's pretty ignorant to not realize that Java IS the more resilient language here. PHP is nice and all, but it has nowhere near the maturity that Java and all associated tools has. - dotdan, on 10/12/2007, -0/+7Okay post, but anyone with a site requiring that technology will already know of them.
Stuff like Smarty will just make code slower on small sites. - scratched, on 10/12/2007, -1/+8I could be wrong, but isn't digg powered by php?
If it is, I think that's a good example of the speed of php. I'd say digg moves pretty quick, especially considering the traffic it gets. - konforce, on 10/12/2007, -0/+5Turck MMCache has long been dead. It shouldn't even be mentioned.
Use http://eaccelerator.net/ instead. - gharding, on 10/12/2007, -0/+5@scratched:
Well, with proper caching (which I'd assume Digg, as well as any other traffic with more than a small amount of traffic would have), it'll basically fly, regardless of what it's written in. Even a site written in Ruby, properly cached, will run pretty quickly!! - gharding, on 10/12/2007, -0/+5That's a popular way, but I usually recommend writing a very simple disk cache in PHP. That way, if for some reason the file is deleted, PHP will fall back and fetch it from the database (and try to make the cache file again). You can set the cache to expire every hour or so, so things stay pretty up to date. Using Cron ends up adding another point of failure and another thing to do if you have to migrate (as well as another thing for a replacement developer to not easily figure out!)
- se7en11, on 10/12/2007, -0/+5My only suggestion would be to make pages that are static..well err static. For example, on my company's website we have a listing of all the categories. (around 250 or so) Rather than having a PHP script query the database, loop through the results and then print that page, we run a CRON job that runs every night to generate this page. Now we just do a simple require() to a static file.
You could do something very similar to a home page. Just have it generate every hour or so if the content doesn't change too much.
Hope it helps someone. - gharding, on 10/12/2007, -1/+6Last I knew, CF was even slower than PHP. And that's pretty bad.
- gharding, on 10/12/2007, -0/+4And as a side note, I'm a Java AND PHP developer for a mid-size financial corporation. I like PHP. I've contributed to a bunch of OS PHP projects, as well as used many others (currently working with Symfony, x-cart, SMF, vBulletin, etc..). I am, however, not deranged enough to not realize that Java is, in the end, more powerful than PHP.
- osmaker, on 10/12/2007, -0/+3PHP = major scripting-type power (think blog software)
Java = major application-type power (think webbased IM solutions) - tempusrob, on 10/12/2007, -0/+3Nice to see a "Faster PHP" blog post that doesn't involve crap like "Use ++$i instead of $i++" and "Don't use double quotes"
- Zoxive, on 10/12/2007, -0/+3Well Digg is running on 90+ servers..
- gharding, on 10/12/2007, -0/+3What, you mean you don't want that 0.00000001% performance increase that saved you less time than it took you to optimize it?
- jstevewhite, on 10/12/2007, -0/+3@java
I'm not at all impressed with the speed or reliability of java - even from those vendors, when installed and configured by their engineers, in many cases replacing binary C code modules that were faster and more reliable. The java stuff tends to leak memory like crazy, and allow stupid ***** like using "connect" with UDP...
I think the ubiquity of Java has little to do with its power or speed - C offers better speed, and most current OS's have a posix subsystem allowing web CGI to be written in C directly without much modification. I think the popularity of Java has more to do with its promotion. Much like VB. People use it because that's what they learned in programming class. - dracula7, on 10/12/2007, -0/+2yea-from my experience the best way to write lightning fast php code is to code minimally.
- Archon810, on 10/12/2007, -0/+2It's almost impossible to cache pages on digg considering that it's very heavy on comments, ratings, and especially comment ratings. How digg keeps its pages so fast has always baffled me.
- superdoug, on 10/12/2007, -0/+2The tips do make php scripts faster, I wouldnt say they make them lightning fast though.
- inactive, on 10/12/2007, -0/+2http://shootout.alioth.debian.org/ has a pretty neat comparison of many popular languages with execution times and memory usage.
Also, people mentioning java don't necessarily mean client-side. Server-side java is actually great because it's so much faster than all of the existing server-side scripting languages. - halfbrown, on 10/12/2007, -0/+2The article is a pretty basic overview of a few items that can help, but not bad if you're a beginning or possibly even an intermediate PHP developer.
WRT the comments from the Java folks, instead of making broad-based statements, how about backing it up with actual stats? Writing something like "Port them to Java." and "It'll make 'em more reliable too. As well as more stable and scalable" makes no sense without proper test cases and unbiased benchmarking. The fact that you can so flippantly make such a statement without a solid base of evidence behind it shows not only your immaturity, but your lack of real (e.g. "professional") development experience.
I'm not saying that PHP is right for everyone and/or everything, but c'mon... make an actual point instead of taking the low road. - courtarro, on 10/12/2007, -1/+3CF is an atrocious, painful language even to look at. A programming language should not be built of -style tags. Performance aside, I say avoid CF like the plague.
- courtarro, on 10/12/2007, -0/+2"Server-side java is actually great because it's so much faster than all of the existing server-side scripting languages."
I wouldn't make such a blanket statement. PHP isn't blazing fast, but Java is hardly the front-runner. They each have situations in which they perform better. A native CGI backend would be the fastest, but it's a pain to code. With a good caching system, all three solutions can be equally fast. - LordMatt, on 10/12/2007, -0/+1As a php developer this get s the thumbs down from me. Sorry fan boys but this is simply php server optimization 101. It has nothing to do with making scripts themselves faster just the server. Further more it boils down to cache and compress. Thanks for that "insight" Sherlock. The lack of a good description should have given the game away but from the title I expected something better.
- mtoigo, on 10/12/2007, -1/+2There are dozens of things that you can criticize PHP for such as loose typing, inconsistent function naming, lack of namespaces, and weak OO. These are all things that would make developing in PHP much easier.
When it comes down to it though PHP just works pretty well for what its meant for and that is small to medium sized web programming projects, and it can properly scale for larger level projects with proper discipline of the developers. - shakin, on 10/12/2007, -0/+1If Smarty does what you want, it's easier to use than rolling your own. It's also easier to cache the entire page output since it's built-in. You just add one line of code: $smarty->caching = true
Smarty does have other problems, like caching a page, but allowing one sub-template on that page to load fresh every time. The syntax isn't perfect. It treats objects like second-class citizens. It all but requires an 'accelerator' or else it's very slow.
Still, it's a great tool and for anyone who doesn't already use a template system, it's a huge step up from nothing. In the PHP world there doesn't seem to be one template system that rules all others. Programmers each have their preferences. - tobyjoe, on 10/12/2007, -0/+1Rails is a framework. PHP is a language.
The speed of each depends on MANY factors, such as how you're handling requests. Apache with mod_php is very, very fast. A dispatch.fcgi process pool running on Mongrel behind Apache 2.2 is very, very fast.
The "very, very fast" is relative, though, and each has their perks.
Now, if you're saying Rails dev is faster than PHP (sans framework) dev, you might be right. Depends on the task. Depends on the test suite chosen, the team proficiency...
I wrote a book on PHP 5 last year. I do very little PHP work these days. My shop evaluates all the tools we have on each project and more often than not, Rails wins out for a number of reasons.
Code execution speed is never a big consideration, though. It's one of the least-important factors. We get insanely high spikes during the Super Bowl, Adult Swim, etc, and as long as we've taken the dozens of steps required to properly optimize an app, we're golden.
This comment, like so many others, has nothing to do with the article ;) - tobyjoe, on 10/12/2007, -0/+1Java has benefits over C beyond PR. Moving higher up offers protections that C doesn't inherently offer. There are also business factors. Recruiting solid Java devs who understand the needs of the Web is much easier than finding solid C devs who are comparable.
Hardware is cheap, and raw speed isn't nearly as important as recruitment costs, consistency in code (style, libs used), investor relations (this is where the PR helps), etc. - rusty_g, on 10/12/2007, -7/+8blog spam, but i guess ok with all the links...
- courtarro, on 10/12/2007, -0/+1@gharding
The point you make is completely valid, and it goes to show that they're two completely different tools for different tasks. PHP is meant for web frontends, while Java beats it raw processing. Java is likely a better tool for lower-level tasks. Java, PHP, C++, C# ... they can all do many of the same things, but each one has an area of focus in which it's the best tool for the job.
In other words, we agree with each other :) - tobyjoe, on 10/12/2007, -0/+1"if you need a fast template system, it'd be better to roll your own anyways. "
I never liked the syntax of Smarty, but I have to say, the NIH syndrome only leads to wasted dev time, no peer review, and lower levels of confidence in code. If something is popular, peer reviewed, and proven, it is NOT (usually) better to roll your own. - courtarro, on 10/12/2007, -0/+1Using a tool like eAccelerator (a maintained fork of the cache mentioned in the artcle) acheives the same goal (caches are basically static) without having the shortcomings of the cron method. Cron only allows you to update pages at a specific interval. The cron method is either updating not often enough, or updating more often than necessary. Using a PHP caching (eAccelerator) system makes it easier to update exactly whenever content changes.
- Archon810, on 10/12/2007, -2/+3Yes, it's so lame that it's the dominating language in website programming.
- courtarro, on 10/12/2007, -1/+2Maybe you're talking about Zend Optimizer, the product that Zend gives away for free on their site? Yes, how lame of a company to give away a language and then try to make money helping you use it. That's only the business model of practically every commercial open-source project out there.
- digrob, on 10/12/2007, -0/+1I would use Ruby on Rails instead, it's much faster than PHP.
- halfbrown, on 10/12/2007, -0/+0@gharding :
Granted... I don't want to build banking apps in PHP either; not yet at least. However, I would prefer to build many other things in PHP vs. Java. Digg, being a perfect example. And there are plenty of examples of large-scale sites using PHP. Yahoo, for example, who famously switched their backend scripting from C to PHP; and they are also using the Symfony framework for their Yahoo! Bookmarks. Want to look at a site that handles lots of traffic and successfully uses PHP? How about Flickr? I could go on, but the following page details more eloquently than I care to at this point the many contentions I have on this topic: http://lesscode.org/2006/03/12/someone-tell-gosling/, with links etc. for perusal.
But I'm not claiming that PHP is perfect either... hell, I'd kill for static typing. And don't get me started on SESSION management with load-balanced servers. But for all of its foibles, it is still (one of) the most popular and prolific languages in use on the Web. And it can be scaled. It can be made to create very fast, very reliable web apps/services/etc. But no, it isn't perfect for everything.
I think if you and I both fast-forwarded this thread to its conclusion, we'd both realize that we are probably talking about the same thing, and that is that you have to choose the right language for the job, and PHP definitely has a place. And yes, I agree that there is also a place for Java.
And FWIW your comment "(I bash all languages.. I work with about a dozen of them daily)" *was* pretty funny. :)
Having said that, let's move on and bash Ruby, then we'll see a REAL turnout for comments! ;P - specb, on 10/12/2007, -1/+1I never understood the desire for Smarty, if you need a fast template system, it'd be better to roll your own anyways.
I'm also suprised eAccelerator wasn't mentioned. If you run a heavily used single server site, it'll give you some nice performance. My load dropped about 10-20% and it's nowhere near as complicated as memcached.
http://eaccelerator.net/ - inactive, on 10/12/2007, -1/+1flickr.com too
- lupinglade, on 10/12/2007, -2/+2php rocks
- halfbrown, on 10/12/2007, -0/+0@courtarro:
Exactly! :) - streaky, on 10/12/2007, -0/+0Uhm.. don't follow any of those ideas until you've rewritten your application to not be *****.
- omerida, on 10/12/2007, -0/+0Rolling your own templating system is a huge waste of time when there are good ones out there and more interesting things you can be developing. I'm not a fan of Smarty either - but I do like phpsavant [phpsavant.com], it uses php for its markup language. (How novel!) So you can still enforce separation between the presentation layer and everything else - which is a good thing.
- fsapo, on 10/12/2007, -1/+1665 diggs... whos gonna be the 666? :)
- Smiechu, on 10/12/2007, -0/+0thx, useful tips :)
- gharding, on 10/12/2007, -3/+2I had hoped.. but at least my joke WOULD have improved performance ;)
(I bash all languages.. I work with about a dozen of them daily) - SnakeO, on 10/12/2007, -2/+1foxstore.com uses smarty
- xenubaba, on 10/12/2007, -2/+1hahaha. which planet r u from?
- noamsml, on 10/12/2007, -2/+1Didn't Zend release a full-blown PHP compiler lately? That would definitely help speed things up.
Oh, BTW, python has automatic object code cacheing. - BasharTeg, on 10/12/2007, -3/+1You should check out Phalanger.
http://www.codeplex.com/Phalanger
It integrates PHP with ASP.NET, pre-compiling your PHP into MSIL, the same way eAccelerator and others pre-compile scripts. The difference is, it’s done by ASP.NET, and your scripts run on IIS6. With your scripts running on ASP.NET, they’re running managed which protects you from a great deal of security issues.
As for performance, I suggest you give it a try, because our tests show PHP running under ASP.NET under IIS6 under Windows 2003 completely destroys the same hardware running PHP with eAccelerator under Apache Linux 2.6 or FreeBSD. Sounds hard to believe, but we’re a shop full of linux/unix guys and all our stuff is currently on Apache and we gave ASP.NET a chance at running our PHP and the results were stunning.
Phalanger gives you the ability to use the .NET framework in your PHP scripts, and to use the code behind model of ASP.NET, but you don’t have to use that stuff if you don’t want to! It is 100% compatible with existing classic style PHP scripts, and PHP modules.
I’m no microsoft fanboi, but if you’re a real developer you shouldn’t be a unix fanboi either, you should test things out and see what works best for you. I highly recommend you test Phalanger with your existing PHP codebase. - MisterRibs, on 10/12/2007, -3/+0gharding:
It was a joke... I just like poking fun at the java fundamentalists from time to time ;)
I should've wrote.. or you could use javascript to document.write every line - woulda made the joke more apparent.
My apologies if it seemed like I was endorsing cold fusion in any manner ;) -
Show 51 - 56 of 56 discussions



What is Digg?
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official