The Apostles Query

Saw this on my feed the other day:

Beautiful queries

“Just wrote the most complex SQL statement I have ever written. It won’t scale, but it’s so beautiful. :)”

Cal’s query brought tears to my eyes. When a finch landed on it, I saw it pivot. It was deeply religious…

START TRANSACTION;

I believe in Codd, the Father Almighty,
CREATE‘r of OLTP and OLAP;

and in MySQL, His PRIMARY KEY, our INDEX:
Which was established by the DB driver,
born of the Open Source;
suffered under Larry Ellison,
was TRUNCATE’d, DELETE’d and was DROP’d.
It INSERT’d INTO NULL;
ON DATEDIFF = 3, It TRIGGER’d again FROM HEAP;
It RAISE()ed into non-TEMP, RIGHT JOIN’d with Codd the Father Almighty;
from thence It shall come to SELECT FROM the relational and non-relational.

I believe in the DB driver,
the Fourth Normal Form,
the relations of tables,
the ROLLBACK of failed transactions,
the RESTORE from logical backups,
and the persistence of storage.

COMMIT;

Next up: Ave MariaDB.

Faster PHP fo shizzle—HipHop for PHP

[This post is in progress. There may be a number of errors. Please comment below with corrections and I’ll update this article.]

Facebook announced the release of HipHop for PHP today.

Haiping Zhao

Haiping Zhao
Facebook, Palo Alto, California

Sony DSC-WX1
1/80sec @ ƒ2.4, ISO400, 4.2mm (24mm)

When I left Plaxo, Haiping was the server architect there. Today, he works at Facebook and announced HipHop for PHP. It’s nice to see the world recognizing his talents.

Since apparently, I was the first person to ever publicly spill the beans on HipHop, I need to do penance by clarifying what HipHop is and what it means for PHP.

For those of you who don’t have time to read the rest, here is what HipHop for PHP is:

  • HipHop is a PHP-to-C++ cross-compiler. What this means is it takes PHP code and translates it into C++ code for further compiling. It is not another language. It is not a just-in-time compiler (JIT).
  • HipHop will be open-sourced by Facebook under the same licensing as the respective PHP codebase it sets to mirror. Facebook hopes that the community will improve HipHop and add extensions to HipHop that mirror PHP functionality. Also, it hopes that future PHP core development will code features that would be more amenable to optimizations that HipHop does.
  • HipHop was the current survivor of a number of projects over the years at Facebook to improve the performance of the site. Facebook, as the second largest trafficked website in the world, is built mostly on PHP. HipHop is currently running side-by-side next to many LAMP PHP servers at Facebook and they are claiming an average of 2x increase in performance on those machines.
  • HipHop accomplishes this by surveying the entire codebase of your PHP-based application with a parser and then building out a C++ project based on it. The C++ project then compiles and runs as its own web server. Because of this, Apache and the PHP Zend engine are completely bypassed.
  • In order for this to work, some features of the PHP language are no longer supported. Also, C-specific PHP extensions will need to be translated to HipHop C++ extensions in order for them to run.
  • The benefit in speed is mostly due HipHop’s static analyzer which parses your PHP code looking for ways to optimize dynamic parts into static maps. Because of this, your performance gain may vary — more structured code is rewarded with larger performance boosts.

What HipHop means

If you use some open-source PHP applications on your hosted website, the answer is nothing. You don’t have the ability to compile HipHop, you don’t have access to server restricted ports, etc.

If you are developing a PHP application that currently can be run on two servers or less (or virtual servers in the cloud) the answer is nothing. You don’t have the scale for this to be worth your time.

If you do not have a separate development and deployment environment, don’t have a developer who knows C/C++, or use any PHP libraries where the source is not available (thankfully the encoded scripting market is small to non-existent in the PHP world), then the answer is nothing. You don’t have the development model that can support HipHop. Also note, HipHop has bugs, and—given the state of APC development as a model—will never have true compatibility with PHP. You’ll need some resources to either recode around those bugs or fix HipHop.

If you are a developer of an open-source PHP application, then the answer is not much. Most PHP applications will be deployed in a shared-hosted environment. They won’t be using HipHop.

If you are a shared hosting company, the answer is not much. This is because the HipHop parser needs access to all the PHP in an application in order for it to create a working project. The exception is if you provide software as a service that you maintain (say a static build of WordPress, or a custom site tool written in PHP). You can have HipHop optimize this and get the performance increase.

If PHP is not the operational bottleneck of your web application (your app spends a lot of time waiting on the database, disk, a 3rd party Web API call, etc.), the answer is not yet. At this time, there’s no point in getting a performance gain in PHP. If you don’t know what I’m talking about, your bottleneck is the database. 😉

If you have an application already scaled across many machines, a significant number of them running PHP in processor-intensive tasks, have separate development/deployment, have your entire PHP source code, have modest C/C++ resources, then the answer is possibly. It wouldn’t hurt for a developer there to try a hand at cross-compiling the PHP into HipHop and seeing if it runs. An operational deployment will return about 50% of those machines to a pool for other uses or future growth—or, put differently HipHop will basically double that processing on the same hardware/power.

If you make a turnkey application based on PHP, the answer is somewhat. These are rare, but now you can shrink-wrap PHP into a binary. This isn’t the intended use of HipHop, so some development might have to be done to get this fully supported. Also this is a true binary, not an op-code compile—it cannot run across platforms.

If you are developing a PHP framework, the answer is some. If your framework can compile and run successfully in HipHop, then it should be a good selling point to enterprises in case their application becomes bottlenecked on performance.

If you have highly-cohesive parts of your architecture that fall into above requirements and those parts are weakly-coupled (via API?) to the rest of the system, then the answer is a lot. Those parts can probably benefit from HipHop, and it should be relatively easy to try it.

If you are making a decision on which web language to build your site in, the answer is a heck of a lot. Arguing against PHP for performance reasons no longer holds water. PHP under HipHop will probably now out-benchmark Perl, Python, Ruby and possibly even Java and C#. In practice, you can get the advantages of having a scripting language without operational costs. Moreover, because the target is C++ which is more easy to integrate as a library, if you have a multi-language support, you can now provide C++, Python, and other languages with access to components that have before only been written in PHP (without resorting to a web API).

If you are making an argument to recode your entire site from PHP to some other language, the answer is you just lost that argument. (I never bought the argument of recoding an entire site from another language to PHP.)

There are language features, for better or for worse, that PHP must support and HipHop must not. Because of it’s unique approach to compiling, HipHop will never replace the Zend Engine. Because it doesn’t supersede PHP user-space syntax, HipHop does not and will never change PHP development (much).

HipHop is a showcase. With it the PHP world can point to Facebook as being the busiest site built in a scripting language in the world.

Continue reading about A deeper explanation of HipHop after the jump

Twitter's Retweet API

Twitter
Image via Wikipedia

Apparently, I’ve gotten the beta for Twitter’s new Retweet feature, so I thought I’d use this moment to rant a little bit about the Twitter Retweet API.

The Retweet API is actually a set of five API functions, and, as per Twitter’s horrible documentation habit, they’re spread across one namespace (“statuses”) but two different classes: “timeline methods” and “status methods.”

I’m not sure how I have the retweet beta UI, but traditional retweets aren’t reformatted automatically for me (the first entry is a retweet). *sigh*

Continue reading about Things that annoy me about retweet after the jump

Learning Programming Part 2: Programming Frameworks

A selection of programming language textbooks ...
Image via Wikipedia

(Full disclaimer: I work at Automattic and am a speaker at PHP conferences.)

A couple days ago, Gina Trapani posted an interesting article on learning to program.

This reminds me that some people may take the wrong points away in my last article on the subject, the priority shouldn’t be what language you should learn, but rather, what is going to get you motivated to learn. PHP is a popular language because it naturally invites “immersion” style learning, not because it makes a good teaching language—which it doesn’t. That is, assuming the thing you are immersing in is “building a website”. As I like to say:

PHP is the shortest distance between two points on the web.

In the comments, I wrote:

After [the first] chapter, I’d say [PHP and MySQL Development]offers the most “immersion” gratification (at the least cost) than any other language’s textbook. The chapters are easy and by the end of it you have an eStore written and working from scratch. What do you get at the end of the Learning Python book? And how easy was each subsequent chapter? I’d say much less and much harder.

[Unfortunately,] it’s that first chapter that does the first timer in.

Continue reading about More about learning web programming after the jump.

Senior software Engineer at CBS Interactive

Another PHP job forwarded to me from Linda Lee and Andrew Mager, this time from CBS Interactive (née CNET).

Company: CBS Interactive (formerly CNET networks)
Title: Sr. Software Engineer
Division: GameSpot.com, TV.com, MP3.com
Location: San Francisco, CA

CBS Interactive is looking for Sr. Software Engineers in their Games, Entertainment and Lifestyles division—including GameSpot.com, TV.com, MP3.com and Chow.com. These engineers will play a key role within our development team. Responsibilities will extend to any of the applications associated with division’s initiatives. Real world experience and expertise with Linux, PHP, and MySQL are an absolute must, but a deep understanding of all web technologies from a technical and product perspective is also very important.

Please check out the job description here. You can apply online or email Linda directly at linda [dot] lee [at] cnetnetworks [dot] com.

FOX needs a senior PHP front-end developer

Hmm, it’s been a while since I posted some PHP jobs. (You know this is getting inconvenient. I think I need to just write a job tool for php.net.) Received this rec from a friend filling a position for FOX Interactive Media to work on the American Idol site. They can work in San Francisco, Los Angeles or even Seattle.

(Also, if you are the one flash/actionscript developer out there, contact Diana for positions at FOX sports, etc.)

Contact Diana Schwartz 310.590.4570 or dschwartz at this site.

[Senior Front End Web Developer job description after the jump]Continue reading