News for hackers. Stuff that matters.
Re:Facebook rewrites PHP runtime, will open source on Tuesday by pbiggar on Saturday January 30, 2010 @11:22PM (#1089974)
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).

Re:Facebook rewrites PHP runtime, will open source on Tuesday by zmimon on Saturday January 30, 2010 @11:37PM (#1090001)
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.

Re:Facebook rewrites PHP runtime, will open source on Tuesday by pbiggar on Saturday January 30, 2010 @11:42PM (#1090009)
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.

Re:Facebook rewrites PHP runtime, will open source on Tuesday by leej on Sunday January 31, 2010 @02:05PM (#1090873)
evaluate quercus.
Re:Facebook rewrites PHP runtime, will open source on Tuesday by rgrove on Sunday January 31, 2010 @12:52AM (#1090100)
"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.

Re:Facebook rewrites PHP runtime, will open source on Tuesday by timdorr on Sunday January 31, 2010 @11:37AM (#1090640)
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.
Re:Facebook rewrites PHP runtime, will open source on Tuesday by pvg on Sunday January 31, 2010 @02:54AM (#1090233)
its about 4-5 times slower.

Really? In what actual benchmarks, real world situations?

Re:Facebook rewrites PHP runtime, will open source on Tuesday by pyre on Sunday January 31, 2010 @04:47AM (#1090327)
Note this is only in the interpreter

You did read this part right?

Re:Facebook rewrites PHP runtime, will open source on Tuesday by pvg on Sunday January 31, 2010 @06:41PM (#1091337)
Re:Facebook rewrites PHP runtime, will open source on Tuesday by igouy on Monday February 01, 2010 @06:21PM (#1093782)
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...

Re:Facebook rewrites PHP runtime, will open source on Tuesday by pvg on Monday February 01, 2010 @08:18PM (#1093994)
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.
Re:Facebook rewrites PHP runtime, will open source on Tuesday by igouy on Tuesday February 02, 2010 @12:27PM (#1095419)
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.

Re:Facebook rewrites PHP runtime, will open source on Tuesday by pvg on Tuesday February 02, 2010 @06:56PM (#1096609)
Right. Python is not 4-5 times faster than PHP. That was my point.
Re:Facebook rewrites PHP runtime, will open source on Tuesday by pbiggar on Tuesday February 02, 2010 @05:43PM (#1096425)
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.