function srv_request($type, $params) { $result, $output = exec(SERVER, $type, $params); return $result, $output; } $txn = rand(); $txmax = 1000; $srv = gethostname(); while (42) { $txn = ($txn + 1) % $txmax; $result, $taskid, $data = srv_request("fetch", $srv, $txn); if ($result != OK) { srv_request("cancel", $srv, $txn); continue; } if ($taskid == NO_TASK_AVAILABLE) continue; $pid = fork(); if ($pid == -1) die("fuck"); if ($pid == 0) { $result, $output = do_task($data); if ($result != OK) { srv_request ("fail", $taskid, $output) } else { srv_request ("done", $taksid, $output); } exit; }; }