PHP and JAVA, PHP on JAVA : Quercus

16 July 2007

Sun should have done this a long time ago, but Caucho did it : Quercus !

I quote :

100% Java implementation of PHP 5 released under the Open Source GPL license. Quercus comes with many PHP modules and extensions like PDF, PDO, MySQL, and JSON. Quercus allows for tight integration of Java services with PHP scripts, so using PHP with JMS or Grails is a quick and painless endeavor.

With Quercus, PHP applications automatically take advantage of Java application server features just as connection pooling and clustered sessions.

Quercus implements PHP 5 and a growing list of PHP extensions including APC, iconv, GD, gettext, JSON, MySQL, Oracle, PDF, and Postgres. Many popular PHP application will run as well as, if not better, than the standard PHP interpreter straight out of the box. The growing list of PHP software certified running on Quercus includes DokuWiki, Drupal, Gallery2, Joomla, Mambo, Mantis, MediaWiki, Phorum, phpBB, phpMyAdmin, PHP-Nuke, WordPress and XOOPS.

Quercus presents a new mixed Java/PHP approach to web applications and services where Java and PHP tightly integrate with each other. PHP applications can choose to use Java libraries and technologies like JMS, EJB, SOA frameworks, Hibernate, and Spring. This revolutionary capability is made possible because 1) PHP code is interpreted/compiled into Java and 2) Quercus and its libraries are written entirely in Java. This architecture allows PHP applications and Java libraries to talk directly with one another at the program level. To facilitate this new Java/PHP architecture, Quercus provides and API and interface to expose Java libraries to PHP.

The Quercus .war file can be run on Java application servers such as Glassfish, i.e. it can be run outside of Resin. This .war file includes the Quercus interpreter and the PHP libraries.

Just a few remarks : it is a .war file that can run on other application servers than Resin, this is great ! Some of the features described are only available in the “professional” non-free version of the Resin Server.

URL utf8

16 July 2007

Note about URL and UTF-8 :

  • There is a Firefox option (about:config) network.standard-url.encode-utf8 that you have to activate in order to comply to the standard (see So you can type in an URL with é and it will be converted to %C3%A9 wich is the expected stardard behaviour.
  • According to RFC 3987, URLs must be converted to UTF-8 character encoding. IE and Opera, contrary to the specification, encode the path part of the URL in UTF-8 but encode the query string part of the URL in the encoding of the referring page ! That would be right for POST parameter, but not for GET !!!
  • W3C make it clear too that URL should be encoded in UTF-8 (has some Java example code).
  • In PHP you should use :
    urlencode(utf8_encode('großpösna'))  -> gro%C3%9Fp%C3%B6sna : GOOD
    utf8_decode(urldecode('gro%C3%9Fp%C3%B6sna')); -> großpösna : GOOD

Eclipse PHP debug

16 July 2007

There are 2 plugins to do PHP development in Eclipse (obviously they are incompatible) they both should work with Eclipse 3.3 Europa.
They have almost the same features. PDT gets my preference.

There are 3 differents debug engines : DBG, xdebug and Zend_Debug (close source).

  • XDebug
    There are two different protocols to communicate with the debugger: the old GDB-like command protocol (GDB) which is implemented in Xdebug 1.3 and 2; and the DBGp protocol which is implemented in Xdebug 2.
  • DBG is a full-featured PHP Debugger and Profiler.

Profiling client KCachegrind can read XDebug Profiling files.