Gelunox
Gelunox

Reputation: 792

Java connection to PHP

I'm building a Java based HTTP Server with a plugin system. And I'm trying to find a simple and elegant way to load PHP as a Template Engine plugin. preferably something that also requires very steps for users that install the plugin, for example pointing to the php directory and the plugin does the rest. However, Google is not proving to be very helpful (it doesn't matter what keywords I use the results are rather useless).

I've found several things about a java-php-bridge, which seems like it could work but it's a rather large old (java 1.4 support) library and I've got a feeling that there is a simpler dedicated solution.

I want to be able to push a map with variables to PHP (headers, get vars, custom vars, etc.) and retrieve the parsed PHP back (including headers that have been set and other possible output)

and, if possible, I want to do this with the least possible computing time (e.g. I could call php.exe every time, but if I'm correct that's a rather expensive way to handle it)

Upvotes: 1

Views: 266

Answers (1)

Valera Leontyev
Valera Leontyev

Reputation: 1181

If you want to interact with PHP in web manner (header, request variables and so on), you can use:

  1. CGI mode (slow and not effective, but rather simple).
  2. FastCGI mode (fast and effective, but requires separated FastCGI server to be running).
  3. SAPI (rather fast and effective, but requires separated SAPI server to be running).

You can search for a client Java code to interact with PHP one of this ways. It solution will not be found, you can write you own client part. Fast and effective solution newer will be simple to programmer and end user.

Using C/C++ php engine can be used as library and linked in application (like mod_php in Apache httpd). This is the fastest way. But it's not possible with Java.

Upvotes: 1

Related Questions