.
// This file contains a PHP binding of a web-service interface
// for submitting jobs to a BOINC server.
//
// Functions:
// boinc_abort_batch(): abort a batch
// boinc_estimate_batch(); estimate completion time of a batch
// boinc_get_output_file(): get the URL for an output file
// boinc_get_output_files(): get the URL for zipped batch output
// boinc_query_batch(): get details of a batch
// boinc_query_batches(): get list of batches
// boinc_query_job(): get details of a job
// boinc_retire_batch(): retire a batch; delete output files
// boinc_submit_batch(): submit a batch
//// Implementation stuff follows
function req_to_xml($req, $op) {
$x = "<$op>
$req->authenticator$req->app_name$req->batch_name
";
foreach ($req->jobs as $job) {
$x .= " $job->rsc_fpops_est$job->command_line
";
foreach ($job->input_files as $file) {
$x .= " \n";
$x .= " $file->mode\n";
$x .= " \n";
$x .= " \n";
}
$x .= "
";
}
$x .= "
$op>
";
return $x;
}
function validate_request($req) {
if (!is_object($req)) return "req is not an object";
if (!array_key_exists('project', $req)) return "missing req->project";
if (!array_key_exists('authenticator', $req)) return "missing req->authenticator";
if (!array_key_exists('app_name', $req)) return "missing req->app_name";
if (!array_key_exists('jobs', $req)) return "missing req->jobs";
if (!is_array($req->jobs)) return "req->jobs is not an array";
foreach ($req->jobs as $job) {
// other checks
}
return null;
}
function do_http_op($req, $xml, $op) {
$ch = curl_init("$req->project/submit_rpc_handler.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// see if we need to send any files
//
$nfiles = 0;
$post = array();
$post["request"] = $xml;
$cwd = getcwd();
if ($op == "submit_batch") {
foreach ($req->jobs as $job) {
foreach ($job->input_files as $file) {
if ($file->mode == "inline") {
$path = realpath("$cwd/$file->path");
$post["file$nfiles"] = $path;
$nfiles++;
}
}
}
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$reply = curl_exec($ch);
if (!$reply) return array(null, "HTTP error");
$r = simplexml_load_string($reply);
if (!$r) return array(null, "Can't parse reply XML: