0

I'm not entirely sure the wording for the title is correct, but what I'm attempting to do is run and execute PHP files from within the Lift framework.

I'm not after any url queries to a PHP file residing on a server, more interested in somehow getting the PHP runtime working through my Scala/Lift app.

Use case: I have my app packaged into a .war file, I host this via a cloud provider. I upload code snippets to said app which then runs the php file and does whatever necessary.

I've seen various posts regarding Bianca but am hoping to keep this setup light and require only the PHP binary itself and a little code to get it flying.

Thanks in advance, please let me know if you need me to elaborate :)

jahilldev
  • 3,520
  • 4
  • 35
  • 52
  • are you talking about running a php file as a script, that, for example, could copy files around your server, or something like that? – fmpwizard Mar 12 '13 at 04:34

2 Answers2

3

“Never say never, because limits, like fears, are often just an illusion.”

― Michael Jordan

What you really need is an open source (GPL), embeddable, full PHP 5 implementation, written entirely in Java!

Caucho's Quercus PHP Java runtime is just that, and it will let you run PHP within a Java app without external libraries or native code.

Below is a Quercus-PHP-in-Java code sample I found in this answer

import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;

QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();

String phpCode = "<?php $foo = strlen('abc'); print $foo; return 'yikes'; ?>"; //PHP Code as String
Object o = engine.eval(phpCode);
System.out.println(o);

It should be little effort to convert this code to idiomatic Scala. Obviously, the 'phpCode' variable could be constructed from external PHP file contents etc.

Let us know how you get on ;-)

Community
  • 1
  • 1
Big Rich
  • 5,864
  • 1
  • 40
  • 64
0

That's a bit of an odd requirement, but if it's what you need to do, you can use a ProcessBuilder to execute and interact with your PHP script from the command line.

Dave Whittaker
  • 3,102
  • 13
  • 14