DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Languages
  4. PHP on a Java application server

PHP on a Java application server

Giorgio Sironi user avatar by
Giorgio Sironi
·
Nov. 01, 11 · Interview
Like (0)
Save
Tweet
Share
13.63K Views

Join the DZone community and get the full member experience.

Join For Free

Let's say we want to run PHP but we have only an available hosting for Java. An example provided from Resin documentation would be to have an easy way to improve performance, or to gain distributed sessions support for PHP.

A very realistic example would be for the integration of Java and PHP applications: with Resin's Caucho, you can actually run Java and PHP code in the same script. For example, you could take a library available only for one of the two languages and use it on the other side without resorting to different processes that communicate.

The solution that was proposed to my team for running PHP code in a Java environment is Quercus, a module for the Resin application server.

Hello world

Resin is an application server which comes complete of a web front end. We downloaded the latest 4.x version and placed in the ROOT webapp folder a WEB-INF/resin-web.xml file for configuration.

The default proposed behavior is to forward any request ending in .php to an interpreter, but the matcher could just be * if you only need to serve PHP files.

A note for PHPers: servlets are roughly the equivalent of action controllers in our MVC frameworks. Each request for a PHP file is intercepted by the servlet shipped in Quercus, which is able to read the complete request and open the file for execution.

The Hello World example indeed works after only taking a few seconds for configuration. Wonderful, given the complexity of translating a language into another.

Let's try our test suite...

Since PHP has no language specification but just a single implementation, there is no guarantee that the PHP core's would be identical to Quercus in behavior.

We had to be sure that nothing broke by running the test suite of the application, to ensure there were no corner cases in the behavior of array_search() or query size limit in PDO, or any other departure from the official PHP interpreter.

Fortunately, Quercus does not only run PHP code through its servlet, but also via the command line:

java -cp resin.jar script.php

We can use this command to start PHPUnit. After all, /usr/bin/phpunit always links to a PHP file:

java -cp resin.jar /usr/bin/phpunit

The default include_path was .:/usr/share/php, which is exactly like ours include_path on Ubuntu. So no problem with including PHPUnit files or other PEAR stuff.

Here come the problems

However, we found out that some of the classes are implemented in userland (with PHP code instead of with compiled Java code). FilterIterator for example is a class shipped by the PHP core but added as a .php file by Quercus. This kind of implementation may impact performance if your code heavily relies on SPL data structures.

Moreover, at least FilterIterator was not available in the cli version. This could be fixed as we run a pair of class_exists() through the web interface and it found the files. To continue the experiment, we tried even to run PHPUnit in the browser with Matt Mueller's PHPUnit Test Report. We downloaded the package and placed it in the document root only to discover that...

Some classes are missing

Some classes are really missing: RecursiveDirectoryIterator, part of the Standard PHP Library and a dependency of Doctrine 2 and Zend Framework, is not implemented.

We found out there is a fork of Quercus maintained by CleverCloud, which supports more classes and has an open ticket recognizing the need for completing the SPL implementation. The implementations are pure Java this time. Unfortunately, RecursiveDirectoryIterator is not in the relevant branch.

We wrote to the sales team to see if the pro version has better support, but probably it will be focused on non functional requirements like performance.

Conclusions

Resin is a famous and reliable application server for Java applications. However, many of the famous testimonials such as salesforce.com are based on Java technologies and not on its PHP support.

You can easily integrate Java and some new lines of PHP code with Quercus: the setup is really easy. But don't assume that you will be seamlessly able to run an existing PHP application on Resin out of the box: we were unable to run PHPUnit, or an application based on Doctrine2 due to missing implementations. This is the current state of Quercus, but we hope the support improves to furnish PHP developers with yet another option.

PHP application Java (programming language) Application server

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Real-Time Analytics for IoT
  • Reliability Is Slowing You Down
  • Testing Repository Adapters With Hexagonal Architecture
  • Cloud Performance Engineering

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: