Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP to Java migration

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?

like image 346
Timo Westkämper Avatar asked Aug 31 '10 16:08

Timo Westkämper


People also ask

Can I switch from PHP to Java?

If you know PHP well enough, you already know how to program. Therefore, you already have a head start, and making the switch to Java will not be nearly as difficult as someone entirely new to programming. Java is more than just a programming language.

Can I use PHP with Java?

There are two possible ways to bridge PHP and Java: you can either integrate PHP into a Java Servlet environment, which is the more stable and efficient solution, or integrate Java support into PHP. The former is provided by a SAPI module that interfaces with the Servlet server, the latter by this Java extension.


3 Answers

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.

like image 123
Mick Sear Avatar answered Oct 02 '22 17:10

Mick Sear


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)

like image 38
schuilr Avatar answered Oct 02 '22 18:10

schuilr


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.

like image 39
Sarfraz Avatar answered Oct 02 '22 16:10

Sarfraz