Changeset View
Changeset View
Standalone View
Standalone View
src/future/exec/ExecFuture.php
| Show First 20 Lines • Show All 225 Lines • ▼ Show 20 Lines | public function write($data, $keep_pipe = false) { | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| /** | /** | ||||
| * Permanently discard the stdout and stderr buffers and reset the read | * Permanently discard the stdout and stderr buffers and reset the read | ||||
| * cursors. This is basically useful only if you are streaming a large amount | * cursors. This is basically useful only if you are streaming a large amount | ||||
| * of data from some process: | * of data from some process. | ||||
| * | |||||
| * $future = new ExecFuture('zcat huge_file.gz'); | |||||
| * do { | |||||
| * $done = $future->resolve(0.1); // Every 100ms, | |||||
| * list($stdout) = $future->read(); // read output... | |||||
| * echo $stdout; // send it somewhere... | |||||
| * $future->discardBuffers(); // and then free the buffers. | |||||
| * } while ($done === null); | |||||
| * | * | ||||
| * Conceivably you might also need to do this if you're writing a client using | * Conceivably you might also need to do this if you're writing a client using | ||||
| * @{class:ExecFuture} and `netcat`, but you probably should not do that. | * @{class:ExecFuture} and `netcat`, but you probably should not do that. | ||||
| * | * | ||||
| * NOTE: This completely discards the data. It won't be available when the | * NOTE: This completely discards the data. It won't be available when the | ||||
| * future resolves. This is almost certainly only useful if you need the | * future resolves. This is almost certainly only useful if you need the | ||||
| * buffer memory for some reason. | * buffer memory for some reason. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | /* -( Resolving Execution )------------------------------------------------ */ | ||||
| * | * | ||||
| * list($stdout, $stderr) = $future->resolvex(); | * list($stdout, $stderr) = $future->resolvex(); | ||||
| * | * | ||||
| * @param float Optional timeout after which resolution will pause and | * @param float Optional timeout after which resolution will pause and | ||||
| * execution will return to the caller. | * execution will return to the caller. | ||||
| * @return pair <$stdout, $stderr> pair. | * @return pair <$stdout, $stderr> pair. | ||||
| * @task resolve | * @task resolve | ||||
| */ | */ | ||||
| public function resolvex($timeout = null) { | public function resolvex() { | ||||
| list($err, $stdout, $stderr) = $this->resolve($timeout); | list($err, $stdout, $stderr) = $this->resolve(); | ||||
| if ($err) { | if ($err) { | ||||
| $cmd = $this->getCommand(); | $cmd = $this->getCommand(); | ||||
| if ($this->getWasKilledByTimeout()) { | if ($this->getWasKilledByTimeout()) { | ||||
| // NOTE: The timeout can be a float and PhutilNumber only handles | // NOTE: The timeout can be a float and PhutilNumber only handles | ||||
| // integers, so just use "%s" to render it. | // integers, so just use "%s" to render it. | ||||
| $message = pht( | $message = pht( | ||||
| 'Command killed by timeout after running for more than %s seconds.', | 'Command killed by timeout after running for more than %s seconds.', | ||||
| Show All 18 Lines | /* -( Resolving Execution )------------------------------------------------ */ | ||||
| * @{method:resolvex}, but also throws if stderr is nonempty, or stdout is not | * @{method:resolvex}, but also throws if stderr is nonempty, or stdout is not | ||||
| * valid JSON. Returns a PHP array, decoded from the JSON command output. | * valid JSON. Returns a PHP array, decoded from the JSON command output. | ||||
| * | * | ||||
| * @param float Optional timeout after which resolution will pause and | * @param float Optional timeout after which resolution will pause and | ||||
| * execution will return to the caller. | * execution will return to the caller. | ||||
| * @return array PHP array, decoded from JSON command output. | * @return array PHP array, decoded from JSON command output. | ||||
| * @task resolve | * @task resolve | ||||
| */ | */ | ||||
| public function resolveJSON($timeout = null) { | public function resolveJSON() { | ||||
| list($stdout, $stderr) = $this->resolvex($timeout); | list($stdout, $stderr) = $this->resolvex(); | ||||
| if (strlen($stderr)) { | if (strlen($stderr)) { | ||||
| $cmd = $this->getCommand(); | $cmd = $this->getCommand(); | ||||
| throw new CommandException( | throw new CommandException( | ||||
| pht( | pht( | ||||
| "JSON command '%s' emitted text to stderr when none was expected: %d", | "JSON command '%s' emitted text to stderr when none was expected: %d", | ||||
| $cmd, | $cmd, | ||||
| $stderr), | $stderr), | ||||
| $cmd, | $cmd, | ||||
| ▲ Show 20 Lines • Show All 592 Lines • Show Last 20 Lines | |||||