18 $me [-j <max_jobs>] [-f <jobs_file>]
27 $me = array_shift($argv);
29 $jobsFile =
'php://stdin';
30 while (count($argv) > 0) {
31 $arg = array_shift($argv);
40 $maxJobs = array_shift($argv);
41 if ($maxJobs === null) {
42 printf(
"Missing value after '-j' argument!");
46 if ($maxJobs ==
'auto') {
49 $maxJobs = (int)(($maxJobs > 0) ? $maxJobs : 1);
53 $jobsFile = array_shift($argv);
54 if ($jobsFile === null) {
55 printf(
"Missing file after '-f' argument!");
59 if ($jobsFile ===
'-') {
60 $jobsFile =
'php://stdin';
67 printf(
"Unknown argument '%s'.\n",
$arg);
73 $commands = file($jobsFile);
74 if ($commands ===
false) {
75 printf(
"Error reading content from jobs file '%s'!", $jobsFile);
80 $statusList = array();
81 $runningJobs = array();
84 if (preg_match(
'/^\s*(#.*)?$/', $command)) {
87 while (count($runningJobs) >= $maxJobs) {
88 waitJob($runningJobs, $statusList);
92 printf(
"Error: spawnJob() returned with unexpected error (running jobs = %d, maxJobs = %d)!", count($runningJobs) , $maxJobs);
93 $globalStatus =
false;
99 while (count($runningJobs) > 0) {
100 waitJob($runningJobs, $statusList);
102 foreach ($statusList as
$status) {
103 $globalStatus&= ($status === 0);
105 exit($globalStatus ? 0 : 1);
139 printf(
"Error: pcntl_wait() returned with unexpected error!");
142 if (!isset($runningJobs[$pid])) {
143 printf(
"Weird: process with PID %d (status %d) is not one of my child...\n", $pid,
$status);
145 unset($runningJobs[$pid]);
156 $cpuinfo = @file(
"/proc/cpuinfo");
157 if ($cpuinfo ===
false) {
160 return array_reduce($cpuinfo,
function ($count, $line)
162 if (preg_match(
'/^processor\s*:\s*\d+$/', $line)) {
waitJob(&$runningJobs, &$statusList)