Notes Information Apocalypse

Is PHP Doomed?

There's a tide of opinion suggesting that PHP is threatened with extinction as standard hardware begins to favour widening multicore processors. This would be a fair argument if PHP was a general purpose systems language, but it's not. It is designed specifically for running dynamically generated websites. Sure, it can be put to other more general purpose tasks, but serving web content is its primary goal.

So how was something so supposedly fundamental as threading left out of PHP? Intentionally, it turns out - that's the whole model of how the language works. PHP is embedded in a shared nothing architecture designed for massive horizontal scalability by throwing out the concept of persistent process state. Every web request handled by a PHP server runs inside its own stateless sandbox and is torn down when processing is completed. Apache is responsible for allocating resources - PHP application code is purely concerned with domain logic and request/response interaction. This model has helped sites like Flickr and Facebook grow enormously fast, due to the fact that they can funnel requests off to any server in a cluster without needing to change their basic application architecture. Lack of threading support is a strength, not a weakness in these cases, because it turns out that simple trumps sophisticated when you start to deal with millions of users - the main bottleneck is access to the persistent data store. When a website reaches this scale, the particular application language in play really does not matter too much.

If web application developers need to start juggling multiple threads, it's probable that they will find it necessary to rework parts of the web server itself, and this is well outside the scope of what PHP is designed to do. That's what C extensions are for. So it's hard to see how PHP will be worse affected than other popular names which do support multithreading. Languages competing with PHP like Python and Ruby are not exactly shining examples of how to implement support for concurrency in a language. PHP is not alone in looking fragile by comparison. That's one of the main reasons why Erlang has been receiving a lot of recent attention, priming it for enterprise use, and It is worth bearing in mind, as Sam Ruby rightly points out, that memory burning PHP, Ruby, or Python processes are hot, clanky, and inefficient: Green Hardware needs Green Software.

PHP may be doomed for many reasons. Multicore processing is unlikely to be one of the primary ones.