openCPU-client-php is a PHP library that works as a client for the OpenCPU Server (https://www.opencpu.org/) and it was built with flexibility and maintainability in mind.
The recommended way to install openCPU-client-php is through Composer
. Just create a composer.json
file and run the php composer.phar install
command to install it:
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/openSILEX/opencpu-client-php"
}
],
"require": {
"openSILEX/opencpu-client-php": "dev-master"
}
}
Configure examples :
After installing openCPU-client-php (through "Composer"
), put the examples directory in a web server accessible path.
Set the right vendor path.
After you will be able to use the code snippet below. You will able to find more examples (asynchronous request support also) inexamples/openCPUCalls.php
.
// Require librairy
require_once '../vendor/autoload.php';
// Require classes
use openSILEX\opencpuClientPHP\OpenCPUServer;
use openSILEX\opencpuClientPHP\classes\OCPUSession;
// connexion to the opencpu server
$ocall = new OpenCPUServer("https://cloud.opencpu.org/ocpu/");
// connexion status
print_r("Server status : " . $ocall->status(true));
// array parameters
$parameters1 = array("x" => "500000");
// call R function
$sessionInstance1 = $ocall->makeRCall("base", "identity", $parameters1);
print_r("Source Session $sessionInstance1->sessionId: " . $sessionInstance1->getSource());
print_r("Session $sessionInstance1->sessionId: " . $sessionInstance1->getObjects());