1

Possible Duplicate:
Call Java method from PHP5

For a time now, I've been searching on how to embed java in php but found questions that give possible solutions and others that say it's impossible.

I happen to have some java code working and I need it working in a php application, I tried making the same exact code in php language (of course, in php) but it doesn't work, so, what I want to know is:

How can I run my java functions using php?

Thank you all.

Community
  • 1
  • 1
Sascuash
  • 3,661
  • 10
  • 46
  • 65
  • *"I tried making the same exact code in php but it doesn't work"* -Well, if it was the *same exact code* then that's not really surprising, since PHP can't interpret Java code. If implementing the functionality in PHP isn't an option (though it really should be) then perhaps you could package the Java code into an application or some sort of standalone service that the PHP code would call? From within the PHP code's domain it should make no difference, it's just calling a dependency regardless of how or where that dependency is implemented. – David Jul 12 '12 at 08:25
  • That's the problem, I don't know how to package the java code so PHP can call it. – Sascuash Jul 12 '12 at 10:22
  • PHP can't call it directly (at least not without some kind of intermediary tool, and I don't know of any). You're probably better off setting up the Java code into an application context of its own (a web service, a local application, etc.) and then just have PHP call that application (a web service call, running a command-line application and checking its output, etc.). (Again, this is if the Java code's logic can't simply be re-implemented in PHP, which I suspect it can. _That_ would really be best.) – David Jul 12 '12 at 10:33

2 Answers2

0

You can give a try to PhpJavaBridge I use it on a project, you can call methods for example from PHP to Java.

But we do that because we got 2 different server, if you got the choice just use one techno.

Cengiz
  • 5,375
  • 6
  • 52
  • 77
Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
  • It's a good solution, but I'm on a mac and there's something that doesn't allow me to use it, that's why asked for possible solutions – Sascuash Jul 12 '12 at 10:38
0

You should ask yourself what the right technology, architecture and programming language for your actual problem is and how it relates to your overall strategy especially regarding skills. You should use the "right" tools for a given problem while trying to limit your skills to a set of tools that are suitable to solve a large scale of your problems. If you need PHP for certain web features in your case you could investigate calling Java server functions e.g. via REST or other communication technologies.

andig
  • 13,378
  • 13
  • 61
  • 98