/**
  * Calls createWork() to generate work units, and calls process_work() on
  * fork_daemon.
  *
  * @throws Exception If createWork() returns a non-array.
  * @return void
  */
 public function start()
 {
     $work = $this->createWork();
     if (is_array($work)) {
         $this->addWork($work);
     } elseif (!is_null($work)) {
         throw new Exception("createWork() may only return an array!");
     }
     $this->fork_daemon->process_work(true);
     $this->logger->info("All children exited, fin!");
 }
 /**
  * Adds a job to the fork_daemon work list so we'll start it.
  *
  * @param string $class Job class to start.
  * @return void
  */
 protected function queueJob($class)
 {
     $this->logger->info("Adding job {$this->jobs[$class]->getReflection()->getShortName()} to work list");
     // Update runtime now, so that subsequent calls to run()
     // dont kick the job off multiple times
     $this->jobs[$class]->setLastRunTimeStart(time());
     $this->fork_daemon->addwork(array($class), $class, $class);
     $this->fork_daemon->process_work(false, $class);
 }
Beispiel #3
0
declare (ticks=1);
namespace PHPMD\TextUI;

use CodeClimate\PHPMD\Runner;
error_reporting(E_ERROR | E_PARSE | E_NOTICE);
date_default_timezone_set('UTC');
ini_set('memory_limit', -1);
require_once __DIR__ . '/vendor/autoload.php';
require_once "JSONRenderer.php";
require_once "Runner.php";
require_once "Category.php";
use PHPMD\PHPMD;
use PHPMD\RuleSetFactory;
use PHPMD\Writer\StreamWriter;
use PHPMD\Renderer\JSONRenderer;
// obtain the config
$config = json_decode(file_get_contents('/config.json'), true);
// setup forking daemon
$server = new \fork_daemon();
$server->max_children_set(3);
$server->max_work_per_child_set(50);
$server->store_result_set(true);
$runner = new Runner($config, $server);
$server->register_child_run(array($runner, "run"));
$runner->queueDirectory("/code");
$server->process_work(true);
foreach ($server->get_all_results() as $result_file) {
    echo file_get_contents($result_file);
    unlink($result_file);
}