Caucho Forums

Caucho Forums (http://forum.caucho.com//index.php)
-   Quercus (http://forum.caucho.com//forumdisplay.php?f=5)
-   -   Using PHP class in Java (http://forum.caucho.com//showthread.php?t=28591)

bentheboffin 12-12-2011 12:16 AM

Using PHP class in Java
 
I need to use a class created in PHP in Java. I figure this should be straightforward using Quercus but can't work out out how to do it. (All the documentation & examples I've found are the other way around - ie using Java in PHP)

I have seen references to Quercus creating .java files from the php code in a /work/ folder. I think this would give me what I need as I could then incorporate these files into my Java project, but I can't seem to find these files anywhere (despite searching my entire computer by modified date!).

Any help would be much appreciated (including telling me if this is actually impossible and therefore saving me from wasting time trying to figure it out!).

adam 03-01-2012 03:34 AM

A few times I have needed php functions in Java. I have not found a direct way to do this, but something I have done in the past is call the php code from java/jsp/servlet and then just capture the output.

Since it typically happens in the same app server, there is very little overhead. Something to this effect


Code:

ArrayList<String> phpOut= new ArrayList<String>();
URL u = new URL("url_to_php");
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String temp = in.readLine();
while (temp != null) {
      phpOut.add(temp);
      temp = in.readLine();
}
// ... process contents of phpOut array



All times are GMT. The time now is 09:48 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.