['pipe', 'w'], 2 => ['pipe', 'w']], $pipes ); if (!is_resource($process)) { throw new RuntimeException('could not spawn ' . basename($script)); } $stdout = (string) stream_get_contents($pipes[1]); $stderr = (string) stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $status = proc_close($process); if ($status !== 0) { throw new RuntimeException( basename($script) . ' exited ' . $status . ":\n" . trim($stderr) ); } $verdict = json_decode(trim($stdout), true); if (!is_array($verdict)) { throw new RuntimeException( basename($script) . " printed no JSON verdict:\n" . trim($stdout . "\n" . $stderr) ); } return $verdict; } }