Passing command line style arguments into PHP from Java.

60 views
Skip to first unread message

klov...@gmail.com

unread,
Dec 31, 2014, 2:41:53 PM12/31/14
to caucho-...@googlegroups.com
This may be answered, but I'm having a hard time finding it, or maybe I misunderstand what I've found.

I have a Java process running on a Resin server, that used to call PHP scripts through a shell out.

I want to move this to Quercus so that we can manage our database connections via JNDI, and hopefully get away from some of the awkward shell calls.

We pass in command line arguments to these PHP files, and I'm not sure how I can accomplish the same task through Quercus.

Here's a SSCE

QuercusEngine engine = new QuercusEngine();
engine.setOutputStream(System.out);
engine.executeFile("src/test.php"); //Normally it'd be test.php 1234 compute


The shell example would be

php -f test.php 1234 compute

//test.php
$orderNumber = $argv[1]; //1234
$process = $argv[2]; //compute



I think my answer lies in the QuercusScriptEngine, and/or QuercusContext but I'm struggling to put it all together.

This is the documentation I'm going by: http://javadoc4.caucho.com/overview-summary.html


Thank you

Nam Nguyen

unread,
Dec 31, 2014, 3:47:48 PM12/31/14
to caucho-...@googlegroups.com
Hi,

You should be using QuercusScriptEngine instead with Java's ScriptEngine
API:

QuercusScriptEngine engine = new QuercusScriptEngine();

engine.put("orderNumber", orderNumber);
engine.put("process", process);

engine.eval(reader);

http://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngine.html

-- Nam

ad...@cs.miami.edu

unread,
Jan 13, 2015, 7:43:53 PM1/13/15
to caucho-...@googlegroups.com, n...@caucho.com
Nam and group,

When I use the QuercusScriptEngine as outside of the standard Queuers Servlet, there seems to be a memory leak (or something like that).

I would like to use Quercus as a scripting language for Java.  However, when I run the QuerucsScriptEngine several times, the memory seems to go up and up.  Eventually the scripts run so slow (probably due to low memory), and then sometimes a memory crash.  I can up the memory, but that is just a temporary solution.

doing something like seems to cause the problem. Perhaps each creation of a QuercusScriptEngine does not release some resources?  Any thoughts?  Using Jdk 1.6 and interpreted quercus.

forloop() {
   String phpCode = readFile("path to php code")

   QuercusScriptEngine engine = new QuercusScriptEngine();

   engine.put("out", System.out)
   engine.eval(phpCode);
Reply all
Reply to author
Forward
0 new messages