/**
  * Executes the task within the user's config and context.
  * The result or any thrown exception is redeemed to a FutureResult with the same async id.
  * Only to be called by CLI. Will error if called from a web process.
  */
 function execute()
 {
     verifyCallingFromCLI();
     $execStartTime = time();
     $future = new FutureResult($this->asyncId);
     try {
         WorkbenchConfig::destroy();
         // destroy the WorkbenchConfig, if one happens to exist
         $_COOKIE = $this->cookies;
         // reestablish the user's cookies so they'll be picked up by new WorkbenchConfig, if required
         WorkbenchContext::establish($this->connConfig);
         WorkbenchContext::get()->agreeToTerms();
         workbenchLog(LOG_INFO, "FutureTaskExecuteStart", get_class($this) . "-" . $this->asyncId);
         $future->redeem($this->perform());
     } catch (Exception $e) {
         $future->redeem($e);
     }
     workbenchLog(LOG_INFO, "FutureTaskExecuteEnd", get_class($this) . "-" . $this->asyncId . " queueTime=" . ($execStartTime - $this->enqueueTime) . " execTime=" . (time() - $execStartTime));
     WorkbenchContext::get()->release();
     WorkbenchConfig::destroy();
     $_COOKIE = array();
 }
 /**
  * Executes the task within the user's config and context.
  * The result or any thrown exception is redeemed to a FutureResult with the same async id.
  * Only to be called by CLI. Will error if called from a web process.
  */
 function execute()
 {
     verifyCallingFromCLI();
     $execStartTime = time();
     $future = new FutureResult($this->asyncId);
     try {
         WorkbenchConfig::destroy();
         // destroy the WorkbenchConfig, if one happens to exist
         $_SERVER['HTTP_X_REQUEST_ID'] = $this->requestId;
         // reestablish the original requestId for logging
         $_COOKIE = $this->cookies;
         // reestablish the user's cookies so they'll be picked up by new WorkbenchConfig, if required
         WorkbenchContext::establish($this->connConfig);
         WorkbenchContext::get()->agreeToTerms();
         workbenchLog(LOG_INFO, "FutureTaskExecuteStart", array("async_id" => $this->asyncId, "source" => get_class($this), "measure.async.queue_time" => $execStartTime - $this->enqueueTime . "sec"));
         $future->redeem($this->perform());
     } catch (Exception $e) {
         $future->redeem($e);
     }
     workbenchLog(LOG_INFO, "FutureTaskExecuteEnd", array("async_id" => $this->asyncId, "source" => get_class($this), "measure.async.exec_time" => time() - $execStartTime . "sec"));
     WorkbenchContext::get()->release();
     WorkbenchConfig::destroy();
     $_COOKIE = array();
 }
<?php

include_once "session.php";
include_once "shared.php";
include_once "async/futures.php";
session_write_close();
set_exception_handler('handleAllExceptionsNoHeaders');
try {
    echo FutureResult::fromId($_REQUEST['async_id'])->get((int) $_REQUEST['wait_for']);
} catch (TimeoutException $te) {
    httpError("202", "Accepted");
} catch (UnknownAsyncIdException $ue) {
    httpError("404", "Not Found");
}