diff --git a/README.md b/README.md index 2334258..0935550 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ **True concurrency using native threading and multiprocessing for parallelizing code, *without* blocking.** -This library is a component for [Icicle](https://github.com/icicleio/icicle) that provides native threading, multiprocessing, process synchronization, shared memory, and task workers. Like other Icicle components, this library uses [Coroutines](//github.com/icicleio/icicle/wiki/Coroutines) built from [Awaitables](https://github.com/icicleio/icicle/wiki/Awaitables) and [Generators](http://www.php.net/manual/en/language.generators.overview.php) to make writing asynchronous code more like writing synchronous code. +This library is a component for [Icicle](https://github.com/icicleio/icicle) that provides native threading, multiprocessing, process synchronization, shared memory, and task workers. Like other Icicle components, this library uses [Coroutines](https://icicle.io/docs/manual/coroutines/) built from [Awaitables](https://icicle.io/docs/manual/awaitables/) and [Generators](http://www.php.net/manual/en/language.generators.overview.php) to make writing asynchronous code more like writing synchronous code. [![Build Status](https://img.shields.io/travis/icicleio/concurrent/v1.x.svg?style=flat-square)](https://travis-ci.org/icicleio/concurrent) [![Coverage Status](https://img.shields.io/coveralls/icicleio/concurrent/v1.x.svg?style=flat-square)](https://coveralls.io/r/icicleio/concurrent) @@ -23,7 +23,7 @@ To be as flexible as possible, this library comes with a collection of non-block ##### Requirements - PHP 5.5+ for v0.3.x branch (current stable) and v1.x branch (mirrors current stable) -- PHP 7 for v2.0 branch (under development) supporting generator delegation and return expressions +- PHP 7 for v2.0 (master) branch supporting generator delegation and return expressions ##### Suggested @@ -35,7 +35,7 @@ To be as flexible as possible, this library comes with a collection of non-block The recommended way to install is with the [Composer](http://getcomposer.org/) package manager. (See the [Composer installation guide](https://getcomposer.org/doc/00-intro.md) for information on installing and using Composer.) -Run the following command to use Icicle in your project: +Run the following command to use this package in your project: ```bash composer require icicleio/concurrent @@ -52,7 +52,7 @@ You can also manually edit `composer.json` to add this library as a project requ } ``` -## Development and Contributing +### Development and Contributing Interested in contributing to Icicle? Please see our [contributing guidelines](https://github.com/icicleio/icicle/blob/master/CONTRIBUTING.md) in the [Icicle repository](https://github.com/icicleio/icicle). diff --git a/src/Process/Process.php b/src/Process/Process.php index 8da3501..a460b38 100644 --- a/src/Process/Process.php +++ b/src/Process/Process.php @@ -181,10 +181,11 @@ class Process implements ProcessContext $this->poll = Loop\poll($stream, function ($resource) { if (!is_resource($resource) || feof($resource)) { + $this->close($resource); $this->delayed->reject(new ProcessException('Process ended unexpectedly.')); } else { $code = fread($resource, 1); - + $this->close($resource); if (!strlen($code) || !is_numeric($code)) { $this->delayed->reject(new ProcessException('Process ended without providing a status code.')); } else { @@ -192,20 +193,29 @@ class Process implements ProcessContext } } - if (is_resource($resource)) { - fclose($resource); - } - - if (is_resource($this->process)) { - proc_close($this->process); - $this->process = null; - } - - $this->stdin->close(); $this->poll->free(); }); } + /** + * Closes the stream resource provided, the open process handle, and stdin. + * + * @param resource $resource + */ + private function close($resource) + { + if (is_resource($resource)) { + fclose($resource); + } + + if (is_resource($this->process)) { + proc_close($this->process); + $this->process = null; + } + + $this->stdin->close(); + } + /** * @coroutine *