Scaling PHP from the farside

[UPDATE]: Facebook plans to release a rewritten PHP runtime shortly. There was some speculatory report which made claims of a 10Ximprovement over mod_php.

Lately, I've managed to push myself to work on a new (and hopefully useful) pet project. For somebody whose constrained world-view of PHPLand was centered around producing or maintaining MVC frameworks that weren't full of shit bloat, It's been an interesting experience treading previously uncharted territory.

The most bitter truth is complicated
Let's accept it. PHP (for it's 33% share of the web, facebook, wikipedia, yahoo! and everything else included) is a tough nut to scale. The conventional way of scaling the PHP-layer for an application from scratch involves getting your hands dirty in the world of web servers, load balancers, opcode-caches and more.

While clouds do offer out-of-the-box scalability of sorts, They might not be a viable choice for everybody

Ease of portability, Simplicity and abundance of libraries for pretty much everything are some of the things PHP has going well for itself. But PHP does become problematic with performance-demands for process-heavy applications. It's best to make peace with the fact that PHP's best potential is as a language to keep your web-frontend simple and extensible.

Mix and Match

I dabbled with a variety of choices. For what it's worth:

a) PHP + C++ + Swig: PHP Documentation was pretty basic. While it's acceptable that C++ is as efficient as things get for performance wants, I found it too demanding (and therefore constraining) to make this a lasting design choice. Besides, my level of comfort in C++ is questionable at this time, so this choice was scrapped after some consideration.(OT: For all my biases, I *do* believe C++ can do more for the web)

b) PHP + Quercus + Resin: The coolest thing that could happen by far. For those unaware, This white paper says quite a bit. Some obvious advantages of tremendous significance

1) 100% Java implementation of PHP => No pointer-overruns / Segfaults / misc classic PITAs
2) Performance: The white paper speaks for itself. To talk the benchmarks, Quercus (compile mode) would give me close to a 5X improvement over a routine PHP 5.3.0 build and 1.5X over a PHP + APC setup. Very much in the scale of improvement WP, Drupal et al derive. This should hopefully improve as the application matures.
3) Flexibility: Biggest plus of all in terms of a design choice. Seamless integration of Java libs with my PHP-frontend. No bridges attached.
4) Deployment: Google's AppEngine doesn't support PHP. Quercus provides a simple workaround to sort that out for good.

Other Stuff

Looking beyond Quercus, there are quite a few other implementations of PHP; But none quite as impressive:

a) PHC - Compiles PHP Code to C.
b) Roadsend - Ditto, but without the Zend API. Almost as promising as Quercus
c) Project Zero, Phalanger: By IBM and Micro$oft respectively. The former compiles Groovy and PHP (another JVM implementation, like quercus) whilst the latter fuses PHP scripts into .NET. Both of these hoon into Zend API and both these are believed to have major performance concerns.

Looking beyond Apache

Back on the LAMP stack, Most performance concerns are so invariably centered around scaling the SQL layer that the web server bottlenecks assume second priority. Not many people realize early that junking Apache (and it's exotic rewrite rules) for something saner (Like a lighthttpd or nginx) can reduce so much cranial overheat during that performance audit.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.