Quercus: Command Line Interface (CLI)

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
(New page: Quercus 4.0.2+ exposes a command-line interface (CLI) that is easier to use than the javax.script API that comes with Java 1.6. The CLI behaves similarly to PHP's CLI. =Executing a scrip...)
 
 
(2 intermediate revisions by one user not shown)
Line 8: Line 8:
 
</code>
 
</code>
  
Example:
+
==CliQuercus example==
 
<code>
 
<code>
 
   java -cp resin.jar com.caucho.quercus.CliQuercus foo.php
 
   java -cp resin.jar com.caucho.quercus.CliQuercus foo.php
 
</code>
 
</code>
  
 +
==Supported flags==
 
The following optional flags are supported:
 
The following optional flags are supported:
  
Line 19: Line 20:
 
   -d name=value : Sets a php ini value.
 
   -d name=value : Sets a php ini value.
 
</code>
 
</code>
 +
 +
=Programmatically executing PHP scripts from within Java=
 +
The generic method to call PHP scripts from Java is through the javax.script API.  Quercus also offers a simpler interface with the QuercusEngine class.  By default, the output goes to <code>System.out</code>.
 +
 +
==QuercusEngine example==
 +
<code>
 +
  QuercusEngine engine = new QuercusEngine();
 +
  engine.setIni("foo", "bar");
 +
  engine.execute("<?php var_dump(ini_get('foo')); ?>");
 +
</code>
 +
 +
==File example==
 +
<code>
 +
  QuercusEngine engine = new QuercusEngine();
 +
  engine.executeFile("/var/www/index.php");
 +
</code>
 +
 +
==Returning objects example==
 +
<code>
 +
  QuercusEngine engine = new QuercusEngine();
 +
  // a com.caucho.quercus.env.ArrayValue is returned
 +
  Value value = engine.execute("<?php return array(1, 2, 3) ?>");
 +
</code>
 +
 +
=For more information=
 +
See Resin's Javadocs.

Latest revision as of 15:21, 21 October 2009

Quercus 4.0.2+ exposes a command-line interface (CLI) that is easier to use than the javax.script API that comes with Java 1.6. The CLI behaves similarly to PHP's CLI.

Contents

Executing a script on the command line

CliQuercus is the class that contains the public void main() method. To execute a script, you would need to pass in the filename to CliQuercus:

 java -cp resin.jar com.caucho.quercus.CliQuercus [flags] <file> [php-args]

CliQuercus example

 java -cp resin.jar com.caucho.quercus.CliQuercus foo.php

Supported flags

The following optional flags are supported:

 -f            : Explicitly sets the script filename.
 -d name=value : Sets a php ini value.

Programmatically executing PHP scripts from within Java

The generic method to call PHP scripts from Java is through the javax.script API. Quercus also offers a simpler interface with the QuercusEngine class. By default, the output goes to System.out.

QuercusEngine example

 QuercusEngine engine = new QuercusEngine();
 engine.setIni("foo", "bar");
 engine.execute("<?php var_dump(ini_get('foo')); ?>");

File example

 QuercusEngine engine = new QuercusEngine();
 engine.executeFile("/var/www/index.php");

Returning objects example

 QuercusEngine engine = new QuercusEngine();
 // a com.caucho.quercus.env.ArrayValue is returned
 Value value = engine.execute("<?php return array(1, 2, 3) ?>");

For more information

See Resin's Javadocs.

Personal tools