views:

183

answers:

6

We are occasionally in a position to take over PHP based projects, but as we are a Java-house we are searching for ways to turn a PHP-project (or codebase) into a Java-project.

The approaches we came up to work in a mixed Java/PHP context are :

  • PHP in frontend and Java in backend with separate front (PHP+JavaScript) and back (Java+SQL) teams
  • using both technologies in a Java webapp, for example via Quercus with one or multiple teams
  • migrating everything to Java

We haven't tried any of these approaches as we've been lucky enough to have enough Java-only projects to work on.

Do you see other approaches, or have you tried any of the described approaches?

+1  A: 

PHP/Java Bridge may be of your interest:

The PHP/Java Bridge is an implementation of a streaming, XML-based network protocol, which can be used to connect a native script engine, for example PHP, Scheme or Python, with a Java virtual machine. It is up to 50 times faster than local RPC via SOAP, requires less resources on the web-server side. It is faster and more reliable than direct communication via the Java Native Interface, and it requires no additional components to invoke Java procedures from PHP or PHP procedures from Java.

Sarfraz
@Safraz, thanks for the pointer, this might be a technology to be used in the first approach
Timo Westkämper
+1  A: 

PHP in frontend and Java in backend with separate front (PHP+JavaScript) and back (Java+SQL) teams

This is technically feasible using SOAP.

using both technologies in a Java webapp, for example via Quercus with one or multiple teams

I have no idea about this

migrating everything to Java

This is better option, but it will take time depending on the size & complexity of your project.

org.life.java
+1  A: 

NUMITON may be useful for you:

http://java.dzone.com/announcements/automated-translations-php-jav

    The shortest route from PHP to Java

    Numiton offers an automated alternative to migrating PHP codebase. This way, 
established applications can benefit from the advantages offered by Java in its
enterprise-level capacity.

    Some of the risks inherent to any software migration are avoided by using an automated
 translation tool. Our PHPtoJava product performs variable type inference, 
objectualization and other operations in a uniform manner, the resulting appearance and 
behavior being identical to what the users already know.


    Of course, the human factor still plays an important role in the post-translation 
phases: application fine-tuning and functional testing. The speed and accuracy of the 
entire process surpass however those of a manual translation.


    One of the applications we have migrated this way is the well-known forum engine 
phpBB. The translation result, nBB2, powers our own forum and was recently donated to the 
open-source community as a SourceForge project.
dvanaria
@dvanaria, thanks for the pointer. This sounds like an interesting approach, but I believe the result would be Java code which wouldn't follow any J2EE best practices. Multi-tier architecture, AOP managed transactions etc wouldn't be used
Timo Westkämper
+1  A: 

My experiences with Querces are not so good. Maybe it has improved, but when I tried it something like two years ago (a long time, I know) it was far from complete and did not support all functions yet. Also, if your application is using some extensions (e.g. from PECL) you will experience difficulties getting this up and running under Querces.

We're currently in the process of migrating a web application from PHP to Java. We're designing a SOA and we'll probably replace some data access objects in the PHP application with a version that talks to internal webservices. Currently we're using Thrift as protocol for our internal webservices, a framework that also has a client available for PHP. We expect this to increase flexibility during migration (allowing us to do step-by-step migration, rather than all-at-once)

schuilr
@schuilr, thanks for sharing. Thrift sounds like a good approach. Maybe also faster than the PHP/Java Bridge. I haven't tried Quercus myself, but the bechmark results are interesting.
Timo Westkämper
+1  A: 

I've used Quercus. I think that if it supports something like Drupal then it's probably fairly mature. If your PHP app works out of the box, then it offers you a very gradual upgrade path to Java since you can write your own plugins in Java and expose them to the PHP layer, such as using a JDBC back-end.

How easy it is all depends on how well separated the layers are in the PHP application. For example, if the view layer is well separated, you might be able to replace both controller and model logic with a Spring MVC application that uses a 'QuercusView' for the view - you may be able to re-use a lot of the PHP view logic.

You should also consider how you can make a survey of the PHP code - maybe a script that extracts all the function calls, imports etc. so you can quickly test the Quercus support for them.

Sorry, I haven't used the PHP-Java bridge, but I think the Quercus library is pretty mature these days, so that would be my first choice for a staged migration.

Mick Sear
@Mick Sear, thanks for your answer
Timo Westkämper
+1  A: 

I do not have any experience running PHP inside a JVM, but I am betting that IBM does. :) You might consider Project Zero.

http://www.projectzero.org/php/

Seems similar to Querces or that other thing someone linked. The only other thing that you didn't mention that I can think of is to refactor the PHP code because I'm assuming that its an older codebase written in a PHP 4 manner.

LLBBL
@llbbl, thanks for the answer. Project Zero looks interesting.
Timo Westkämper