tags:

views:

139

answers:

6

1 function is written in Java while the API of another function is written in PHP. So, is it possible to use JSP and PHP at the same time?

+4  A: 

I would say that you could call (from your Java code) a different process to execute the PHP script, and then use the output of that PHP script in your Java code -- but that's certainly not optimal, and will not allow you to call only one PHP function.

Using both Java and PHP code in the same application seems a bit complicated, and I've never seen this done -- nor used in any way ; so, I would probably rewrite the PHP code to Java (or the Java code to PHP), so the whole application is written in only one of those two languages.


I've never tried it, but maybe a possibility would be using Quercus -- see, for instance : java and php integration

It seems to be able to run Drupal (a popular PHP CMS ; which means quite a lot of functionnalities) : Running Drupal 6.2 on Resin 3.1.6 ; so I'd say it might be worth a look...

Pascal MARTIN
+1  A: 

There is Java integration available in PHP, but that's for accessing Java classes in PHP and probably won't let you use JSP without a lot of hacking.

Ignacio Vazquez-Abrams
A heck I occasionally perform is copy the resultant servlet precompiled by Tomcat/Jetty from the source JSP and place it within the source package path/namespaces of the application.
Blessed Geek
+1  A: 

You can do it if you are App servers like Resin which support PHP or using experimental PHP / Java Integration. Note that running PHP on Resin may not support all extensions for a given application but I have ran Wordpress on Resin and it's neat.

Chandra Patni
+1  A: 

When you say JSP and PHP, it is a mixed bag. Java and PHP as two languages, OK. But JSP and mod_PHP as two server interfaces, NO.

To run a mod_PHP program you must setup certain (many) server variables which PHP will use. The same to run a Jsp program, the server environment must be established.

But to run a mod_PHP program and call (in some fashion) a Java program, as @Pascal wrote, sure, but the linkage is inefficient. And the same the other way, a JSP program can launch a PHP (CLI) program too.

Don
+1  A: 

In general no. There is, however, a PHP implementation written in Java which will most likely allow you to do what you need which can run in most web containers.

Have a look at Quercus from Caucho. Here is the tutorial: http://quercus.caucho.com/quercus-3.1/examples/quercus.xtp

Thorbjørn Ravn Andersen
A: 

You should consider the following design.

  1. Your PHP pages run on Apache http with the mod.
  2. Your JSP pages run on Apache tomcat.
  3. Run a memory based rdbms.

All three is run on the same system.

Inter PHP-JSP communication would be conducted on two ends:

  1. the frontend JSP and PHP web services
  2. and the backend memory-based rdbms.

Disclaimer: I have never even seen any PHP code in all my 30 years' programming life. Perhaps, once, actually. Therefore, I have faint idea how difficult it might be to have PHP serve web services.

Blessed Geek