Hacker News new | past | comments | ask | show | jobs | submit login

PHP is dirt slow. When you look at the implementations of Lua or Python (which have approximately the same design as PHP), its about 4-5 times slower. Note this is only in the interpreter -- lots of the library code is written in C, which makes the difference somewhat less relevant.

The implication is that writing code that uses PHP's built-in libraries is pretty fast, but the more you write in PHP itself, the slower it gets. For example, my impression is that Yahoo isnt really written in PHP - its written in C patched together using PHP.

The Zend engine was "rewritten" for PHP 4, PHP 5, and to a certain extent for PHP 5.1. I guess it wasn't a complete rewrite because the legacy code from about 10 years ago is still in there. Anyway, its still dirty, badly written, slow, and very very badly commented. Hacks abound (and not the good kind).




This is a point I always have trouble impressing on people. They do a simple benchmarks on a tiny code base that pulls some data from the database, spits out some data, and they compare and PHP seems to be lightning fast.

The problem is that because it's interpreted at some point PHP slows down in proportion to the size of your code base. A small app runs really fast, a big app with 100,000 lines of code will kill your server unless you modularize it really really well - which harder than it seems, because the more modularized you make it the more separate "includes" you end up with in different files and then you come to realize that including a lot of files itself is a problem. And the nature of PHP's very loose coupling tends to lead to code that is nearly impossible to do large scale refactoring on once you have gone too far down the path.

I work on an application that has a very thin PHP layer that performs some simple web services that are the back end for a pure Java web app. Amazingly, when we load test it, the PHP part is the bottleneck, burning CPU like crazy just parsing all our files ... over ... and over ... and over. The java code meanwhile, while theoretically doing far more "work", is completely bored. We will probably look at using an accelerator of some kind or maybe just rewriting all the PHP in another language.


If your problem is parsing time, just use an accelerator. APC is the standard and best integrated.

On the other hand, if you have an opportunity to switch out PHP for something better (read: nearly anything), you should. Otherwise it might grow to a point that you can't remove it.


evaluate quercus.


"For example, my impression is that Yahoo isnt really written in PHP - its written in C patched together using PHP."

Yahoo! is a company, not a single application. Not everything at Yahoo! is written in PHP, but the vast majority of Yahoo! properties do use PHP heavily on the frontend, and not just as a way of patching together C extensions.


Well, if you use APC then that's all irrelevant. It's the equivalent of creating .pyc files. I never got the impression it was slower in actual execution, though.


its about 4-5 times slower.

Really? In what actual benchmarks, real world situations?


Note this is only in the interpreter

You did read this part right?



For the comparison you seem to be interested in choose the measurements where the programs are forced onto a single core

http://shootout.alioth.debian.org/u32/benchmark.php?test=all...


The argument being made was that the PHP runtime is 4-5 times slower than Python and that PHP only looks as fast as it does because of the C libraries. This is simply untrue and the OP wasn't able to back it up. Cores don't come into it.


The Python mandelbrot program uses 4 cores the PHP mandelbrot program uses 1 - that's why Python seems so much faster on mandelbrot.

The Python spectral-norm program uses 4 cores the PHP spectral-norm program uses 1 - that's why Python seems so much faster on spectral-norm.

The Python binary-trees program uses 4 cores the PHP binary-trees program uses 1 - that's why Python seems so much faster on binary-trees.


Right. Python is not 4-5 times faster than PHP. That was my point.


Actually I was basing it off the Language ShootOut. Last time I looked through it properly, Python was 16x slower than C, and PHP was 70x slower.

I wonder why its changed. PHP certainly hasn't gotten faster in the meantime.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: