REX: Remote Execution Framework for PHP
<< Web Interface Back to Contents Using the Framework API >>

Coding REX Files

REX files are simply PHP files with access to a specific framework to support their operation.

PHP code in the files must be prefixed with a <?php and closed with a ?> (like any PHP script).

As the code is executed with a function any PHP variables (other than super-globals) you wish to access or work with must be defined with the global command.

The REX framework object itself is available to REX scripts as $REX and they can access all the the API methods and properties that are available.

Executing Other Files

A REX should make use of the REX::ExecFile() method to call another file. If not prefixed with a protocol (such as http:// or file://) then the file is executed relative to the base directory.

Usually this means the same directory the current REX file is executing from.

<?php
// Do some stuff...
$REX->ExecFile("another.rex");
?>
The above script will "do some stuff" and then execute the file another.rex (if the base directory property is unmodified this will be called from the same directory as the original script.

Variables

REX files can make use of standard PHP variables that are in scope. In effect this means super-globals and anything that is specifically named in a global statement.

Variables persist through the execution of future files so can be used to pass data.

As well as using native PHP variables there are two sets of REX variables; the variable stack and environment variables.

Stack variables are set with REX::Set() and recalled with REX::Get()

<?php
$REX->Set("my_variable","hello");
echo $REX->Get("my_variable");
?>
The above code will set my_variable to be "hello" and then echo it back in the output.

To see more detail on this and also the environment variables please see the API documentation.

A good example showing use of variables is the counter example (available from the examples page.

<< Web Interface Back to Contents Using the Framework API >>