View Full Version : Using PHP class in Java

12-12-2011, 12:16 AM
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!).

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

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