/** * Sets up forking. * * @param fork_daemon $fork_daemon Fork daemon object. * @return void */ public function setUpForking(fork_daemon $fork_daemon) { $this->fork_daemon = $fork_daemon; $this->fork_daemon->max_children_set($this->getNumChildren()); $this->fork_daemon->register_child_run(array($this, 'processWork')); $this->fork_daemon->register_parent_exit(array($this, 'cleanUp')); $this->fork_daemon->max_work_per_child_set($this->getItemCount()); }
/** * This function creates a bucket for each job in fork daemon so it is * easier to manage if it should run or not. * * @param string $class Job to create buckets for. * @return void */ private function createJobBuckets($class) { $job = $this->getJob($class); $this->fork_daemon->add_bucket($class); $this->fork_daemon->max_children_set(1, $class); $this->fork_daemon->register_child_run(array($this, 'processWork'), $class); $this->fork_daemon->register_parent_child_exit(array($this, 'parentChildExit'), $class); $this->fork_daemon->child_max_run_time_set($job->getMaxRunTime(), $class); }
<?php declare (ticks=1); require_once __DIR__ . '/../fork_daemon.php'; /* setup forking daemon */ $server = new fork_daemon(); $server->max_children_set(5); $server->max_work_per_child_set(3); $server->register_child_run("process_child_run"); $server->register_parent_child_exit("process_child_exit"); $server->register_logging("logger", fork_daemon::LOG_LEVEL_ALL); test_identifier(); function test_identifier() { global $server; $server->child_single_work_item_set(true); $server->max_work_per_child_set(1); echo "Adding 100 units of work\n"; /* add work */ $data_set = array(); for ($i = 0; $i < 100; $i++) { $data_set[] = $i; } shuffle($data_set); $data_set = array_chunk($data_set, 3); $i = 0; foreach ($data_set as $item) { $server->addwork($item, "IDn{$i}"); $i++; } echo "Processing work in non-blocking mode\n";
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); }