Skip Navigation Links

PHP is the A.C.E. up Project Zero’s sleeve

Posted by gcuomo on October 5th, 2007. Other posts by gcuomo

Been getting quite a bit of questions about PHP’s place in PZ. Here are some questions and some answers…

Why PHP?

Three words… Agility, Content, Educated. Yes, PHP is the A.C.E. up our sleeve.

Agility. If JEE applications are optimized for “enduring value” (A.k.a. they are written to run forever) then PHP scripts are optimized to “be running by this Friday” (A.k.a., they allow code to be written quickly and compactly, which is fine for many situational applications that spring up.)

Content. We call it “programming by cut-and-paste”. With PHP there are tons of assets available on the net. It is rare that you ever write something from scratch. Search, cut, paste and away you run… (This brings us back to Agile.)

Educated. It is really easy to self-Educate with PHP. It is easy for many people, even for people without formal computer science education, to write PHP scripts. For example, the complexities of Memory management and threading are not at the forefront of your mind when you are scripting in PHP. And back to my last point, much of the time you are modifying someone else’s code.

PHP is not the dynamic scripting language that Ruby or Groovy are.. This much is true. However, these languages have a long way to go before the most popular applications in the world get written on them (think Wordpress, PHPBB, etc.). As long as there are extendable PHP applications, new people will be learning PHP. Given that most of the tools popular with college students are written in PHP, there will continue to be a new breed of PHP programmers for Project Zero to accommodate.

Where is your PHP coming from?

Starting late last year, we’ve been working on a PHP interpreter from scratch in Java to serve as the PHP implementation for Project Zero. Since then, we’ve made some great headway. The wiki pages linked to from our PHP Language support page indicate how much of the language and existing functions we currently support.

Why not PHP.NET?

You might ask – why not use the php.net runtime? You can ask the same question of the JRuby and Jython developers. The answer is, the Java VM can actually reasonably host other programming languages, and in fact there can be some real advantages to having all your runtime code running on a common core.

Where are we at with PHP?

One effort that we identified early, relating to PHP in general, was enhancing the number of test cases that the php.net runtime uses to help maintain release-to-release compatibility. This is based on our experience with the huge number of tests that Java uses for the same purpose. Looking at the PHP tests, we realized that PHP could really use more test cases. And so we sponsored some colleagues to specifically look at adding to the base of test cases. You can see an example of this from the Zend Weekly Summaries Issue.

It should be obvious that we should be able to use these same tests to test our own PHP interpreter, and we’ve been doing this almost from the beginning. We’ve had the developers who are working on our implementation also contribute test cases back to php.net via the QA mailing list, as they’re developing their code.

What are we doing for Tooling?

We’ve been targeting the PHP Development Tools (PDT) extension from Eclipse, which provide a fantastic set of tools for PHP developers using Eclipse. The only real hole for us was the debug story, since the only debug protocol supported was the proprietary Zend debug protocol. Turns out, there’s an open source debug protocol called XDebug available for PHP, and we thought: 1) it would be nice to support this in the PDT itself; 2) we should use this as the debug protocol for our PHP interpreter. Doing both of these, and we’ll have debug capability for our runtime. And so we did. Recent versions of the PDT available from Eclipse are shipping with XDebug support provided by one of our developers. You can see some evidence of this by the noticing the ‘debug’ items in the PDT 1.0 Features Proposal.

What’s coming in PHP?

Obviously, we want everything better, stronger, faster. Where we can, we’re aiming to do things that benefit both the php.net runtime community, and our own interpreter. Most of our efforts in the near future are all about extending the number of functions that we support, since that’s our biggest hole. To put some practical focus on that, we are looking specifically at the phpBB application, to target being able to run it in our own runtime.

Our current story for building new ‘extensions’ for PHP involves an interface we call XAPI-J, which allows you to build extensions for our PHP interpreter in Java much like you would build extensions for the php.runtime in C.

We are also investing an alternative interface we call XAPI-C. Rob Nicholson mentioned this last week in his blog entry PHP Library Progress. The idea with XAPI-C is to take the existing php.net extensions, apply some macro magic, potentially some light code rewrite, and make those extension shared libraries available to Java through JNI. This is similar to the technique that Rubinius is going down for Ruby.

Groovy or PHP?

People sometimes ask me if there is a rule of thumb for using PHP and/or Groovy in Project Zero. My personal opinion would be – If you are a Java engineer, Groovy is the way to start. Java engineers are longing for the agility characteristics that Groovy provides. We want to encourage them that they can have their “cake and eat it too”. Or should I say, they can have their “Java and do Dynamic scripting too”. However, if you don’t have a strong Java background, and/or if you are looking to leverage pre-existing Content on the Web- PHP offers the means to create agile applications quickly.

Anything else?

Our PHP Interpreter is packaged as an independent Ivy package. We’ve adapted the Zero runtime to work with our interpreter, just like we did with Groovy. The advantage to this is that the interpreter might be used in other environments besides Project Zero. We have debated the idea of moving our PHP interpreter (again, like Groovy) into a project unto it’s own – where it can explore better compatibility with php.net as well as pursue supporting a full complement of PHP applications. Thoughts?

- Jerry

5 Responses to “PHP is the A.C.E. up Project Zero’s sleeve”

  1. Austin Putman Says:

    What of quercus? I’m looking for a solution in this area so it’s great to hear that work is being done at Project Zero. I’m not clear on the difference between your strategy and the one used by these folks: http://quercus.caucho.com/

  2. Jerry Says:

    more on our strategy…
    The PZ strategy is to build an agile environment for creating, assembling and executing dynamic web applications. When I say “agility”, I mean quick time to value. One way we achieve agility is via the use of Dynamic Scripting Languages. PZ offers two DSLs. PHP – because of the abundance of PHP skills and content. And Groovy – for the Java programmer looking for more agility. Support for multiple DSLs on a single integrated (java-based) platform is a pretty unique feature of PZ.

    Given the importance of DSLs in PZ, we want to ensure we have best-of-breed implementations. As you probably know, we are blessed with some very strong interpreter and compiler skills in IBM. PZ is utilizing this talent to build a PHP interpreter that leverages our intimate understanding of JVMs (being done in IBM Hursley with help from Raleigh, Ontario, and Tokyo). The goal is to both leverage the underlying Java platform for performance, reliably and scale- and utilize external PHP modules for compatibility with php.net. (again, a pretty unique approach).

    Not to be overlooked is PHP’s integration with the PZ environment. Whether programming in Java, Groovy or PHP – PZ provides and integrated set of tools, conventions (e.g., REST, templates) and utilities (e.g., pureQuery for DB access, Dojo).

    There are many more details, I will let the members of the team chime in…

  3. Rob Nicholson Says:

    more on our strategy…

    So as Jerry says, the PHP interpreter in Zero is a fairly young project in comparison to other dynamic language implementations on the JVM. We are looking for feedback on what we are doing.

    Thus far, our primary focus has been to build a PHP5 implementation which behaves compatibly with the PHP.net implementation. Our intent is to build a runtime that can run PHP5 applications, code snippets, idioms just as they run on PHP.net and which also benefits from the integration with Zero. In order to do this we have been making a lot of use of the PHP test suite hosted at http://qa.php.net/ and indeed IBM has been contributing many tests to this suite this year. Eventually we’d like to work with the PHP QA community to reach a point where the PHP language and all of its core extension libraries are fully covered by a compatibility test suite. As I mentioned in my blog post we are targeting running phpBB as our first proof point of compatibility.

    As I mentioned, we are implementing some of the extension functions in Java using our published XAPI-J interface but where we can we are making use of the existing PHP extensions, implemented in C using an interface we are developing called XAPI-C. One of the significant strengths of PHP is its huge library of extension functions and we see the XAPI-C ultimately allowing us to attach most of this library to Zero. When you set this alongside the Java Bridge giving access to the extensive Java class libraries, what you get is a platform that allows programmers from a wide range of backgrounds to achieve the “time to value” that Jerry mentions above.

    Incidentally, when we test the PHP runtime using the PHP QA suite we do so using a PHP commandline and test runner application. We actually ship the commandline in the zero .jar files but we have not documented it. If you are interested in using the PHP commandline then please let us know using the forum.

  4. foolomon Says:

    Wow
    This is totally irrelevant, but important nonetheless.

    Wow.

    Things are quite a far distance away from when you and I used to jam on our guitars in your office in Yorktown Heights, eh? Good to see where you ended up. Drop me a line some time, and we’ll catch up on what’s happened during the last 15 years.

    - foolomon

  5. dsconnelly Says:

    Maybe when M3 is done, P8 (Project Zero) will run the Smarty PHP Template Engine. At present, you still need to hack on it a bit to get it to work.

    So I tried Smarty on Quercus under Tomcat 5.5. I thought it would be slow(er) than P8. Not so. Blazing fast. Just worked. No hassles. (But no database usage either.)

    Project Zero supports REST conventions using a specialized system of name to object mappings. Having this hardwired will speed the development of NEW applications where you want PHP’s agile development style in the presentation layer for your SOA makeover.

    However, if you want INTEGRATION of existing (pure) PHP applications with JavaEE objects and services (DataSource lookup in particular) where JNDI gives the name to object resolution, then go directly to Quercus. PDO in Quercus is a wrapper for your JavaEE DataSource pool. Other JavaEE services can be similarly mapped (I assume, haven’t tried).

    I emphasize “pure” PHP for Quercus because Quercus cannot absorb extensions implemented in C. Quercus is said to compile PHP code to Java (to bytecodes?). Since I haven’t found any “class” files when I run Smarty with Quercus, I assume the Java classes are loaded to the JVM directly from the scanned PHP files. P8, on the other hand, interprets PHP. This gives Project Zero the freedom to link to native (C) extensions for PHP applications. Many PHP functions in Project Zero are in fact implemented in C. I suspect some manual work is required to convert an arbitrary C extension to JNI.

    Since Project Zero depends on C to run its PHP, one needs to be content with its 32-bit Windows or Linux C libraries. Quercus should run pure PHP on any JVM (Solaris SPARC 64-bit, for instance).

    Backing up, Project Zero excels at giving developers a server-side presentation layer for SOA mashups. This is Internet land. Quercus excels at being a presentation layer for JavaEE services. This is Intranet land.

    - dsconnelly