PHP APIs for Distributed Mode
In your PHP source code, include the necessary code to run your report application.
Provide the remote connection details
In the .php source code, include the
following:
$greRunnerObj = new GreRunner($reportDesignFileName, $reportClassName);
$greRunnerObj->configureDistributedProcessing("GRE_server_name",port);
- GRE_server_name is the name of the server where the GRE is running.
- port is the port number where the GRE is listening.
Simple PHP code sample
...
set_include_path(get_include_path().PATH_SEPARATOR.getenv("PHPINCLUDEDIR"));
require_once 'libgrerunners.php';
class ReportLauncher {
/**
* PDO database connection.
*/
protected $pdo;
/**
* Launch the report
*
* @param reportClassName
* Report class name
* @param reportDesignFileName
* Report design file (4rp)
* @return status
*/
function launchReport($reportClassName, $reportDesignFileName) {
// Configure the report for processing on remote server "huascar" listening on port 1974
$greRunnerObj = new GreRunner($reportDesignFileName, $reportClassName);
$greRunnerObj->configureDistributedProcessing("huascar",1974);
$greRunnerObj->selectDevice('PDF');
$greRunnerObj->selectPreview(false);
// The report file is a .pdf file with an unique name located in the temporary directory
$reportFileName = sys_get_temp_dir().DIRECTORY_SEPARATOR.basename($reportDesignFileName, ".4rp")."_".uniqid().".pdf";
$greRunnerObj->setOutputFileName($reportFileName);
try {
$reportData = new $reportClassName($this->pdo);
$greRunnerObj->run($reportData->getMasterRecord());
echo "PDF Report File created in: ".$reportFileName."\n";
} catch (PDOException $e) {
echo "PDOException: ".$e->getMessage();
return false;
} catch (UserAbortException $e) {
echo "UserAbortException: ".$e->getMessage();
return false;
} catch (GreRuntimeException $e) {
echo "GreRuntimeException: ".$e->getMessage();
return false;
} catch (Exception $e) {
echo "Exception: ".$e->getMessage()."\n";
echo "Info: Report Writer server may not be started. Launch it with the following command: greportwriter -l 7000";
return false;
}
return true;
}
...