From 4ef64e93df8949a6c9feeb73a49b12ae52c9eb58 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 12 Jun 2017 07:57:52 +0200 Subject: [PATCH] Update react/stream to support 0.6, 0.7, and 1.x PHP 5.3 fix Updated to react/stream:^0.7.2 Removed unused React\Stream\Stream import Updated readme to the updated streams As => and https://github.com/reactphp/child-process/pull/38#discussion_r122565661 Use interfaces instead of concrete classes in the documentation https://github.com/reactphp/child-process/pull/38#discussion_r122565742 Line folding --- README.md | 14 ++++++++------ composer.json | 2 +- examples/11-benchmark-read.php | 3 +-- examples/12-benchmark-write.php | 3 +-- examples/13-benchmark-throughput.php | 3 +-- src/Process.php | 10 +++++----- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index cf16272..2da5993 100644 --- a/README.md +++ b/README.md @@ -64,16 +64,18 @@ access fields otherwise available through `proc_get_status()`. ### Stream Properties Once a process is started, its I/O streams will be constructed as instances of -`React\Stream\Stream`. Before `start()` is called, these properties are `null`. -Once a process terminates, the streams will become closed but not unset. +`React\Stream\ReadableStreamInterface` and `React\Stream\WritableStreamInterface`. +Before `start()` is called, these properties are `null`.Once a process terminates, +the streams will become closed but not unset. * `$stdin` * `$stdout` * `$stderr` Each of these implement the underlying -[`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface) -and you can use any of its events and methods as usual: +[`ReadableStreamInterface`](https://github.com/reactphp/stream#readablestreaminterface) or +[`WritableStreamInterface`](https://github.com/reactphp/stream#writablestreaminterface) and +you can use any of their events and methods as usual: ```php $process->stdout->on('data', function ($chunk) { @@ -94,12 +96,12 @@ $process->stdout->on('close', function () { $process->stdin->write($data); $process->stdin->end($data = null); -$process->stdin->close(); // … ``` For more details, see the -[`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface). +[`ReadableStreamInterface`](https://github.com/reactphp/stream#readablestreaminterface) and +[`WritableStreamInterface`](https://github.com/reactphp/stream#writablestreaminterface). ### Command diff --git a/composer.json b/composer.json index cf8e489..975cbb0 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.3.0", "evenement/evenement": "^2.0 || ^1.0", "react/event-loop": "^0.4 || ^0.3", - "react/stream": "^0.5 || ^0.4.4" + "react/stream": "^1.0 || ^0.7.2" }, "require-dev": { "phpunit/phpunit": "^5.0 || ^4.8.10", diff --git a/examples/11-benchmark-read.php b/examples/11-benchmark-read.php index 996a153..0f42b4a 100644 --- a/examples/11-benchmark-read.php +++ b/examples/11-benchmark-read.php @@ -13,8 +13,7 @@ $loop = Factory::create(); -$info = new React\Stream\Stream(STDERR, $loop); -$info->pause(); +$info = new React\Stream\WritableResourceStream(STDERR, $loop); $info->write('Counts number of chunks/bytes received from process STDOUT' . PHP_EOL); $info->write('Command: ' . $cmd . PHP_EOL); if (extension_loaded('xdebug')) { diff --git a/examples/12-benchmark-write.php b/examples/12-benchmark-write.php index 4f88e5e..c2dede4 100644 --- a/examples/12-benchmark-write.php +++ b/examples/12-benchmark-write.php @@ -8,8 +8,7 @@ $loop = Factory::create(); -$info = new React\Stream\Stream(STDERR, $loop); -$info->pause(); +$info = new React\Stream\WritableResourceStream(STDERR, $loop); $info->write('Pipes data to process STDIN' . PHP_EOL); if (extension_loaded('xdebug')) { $info->write('NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL); diff --git a/examples/13-benchmark-throughput.php b/examples/13-benchmark-throughput.php index a4c936c..a0c1df7 100644 --- a/examples/13-benchmark-throughput.php +++ b/examples/13-benchmark-throughput.php @@ -8,8 +8,7 @@ $loop = Factory::create(); -$info = new React\Stream\Stream(STDERR, $loop); -$info->pause(); +$info = new React\Stream\WritableResourceStream(STDERR, $loop); $info->write('Pipes data through process STDIN and reads STDOUT again' . PHP_EOL); if (extension_loaded('xdebug')) { $info->write('NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL); diff --git a/src/Process.php b/src/Process.php index eab8afb..537b5ab 100644 --- a/src/Process.php +++ b/src/Process.php @@ -5,7 +5,8 @@ use Evenement\EventEmitter; use React\EventLoop\LoopInterface; use React\EventLoop\Timer\TimerInterface; -use React\Stream\Stream; +use React\Stream\ReadableResourceStream; +use React\Stream\WritableResourceStream; /** * Process component. @@ -120,11 +121,10 @@ public function start(LoopInterface $loop, $interval = 0.1) }); }; - $this->stdin = new Stream($this->pipes[0], $loop); - $this->stdin->pause(); - $this->stdout = new Stream($this->pipes[1], $loop); + $this->stdin = new WritableResourceStream($this->pipes[0], $loop); + $this->stdout = new ReadableResourceStream($this->pipes[1], $loop); $this->stdout->on('close', $streamCloseHandler); - $this->stderr = new Stream($this->pipes[2], $loop); + $this->stderr = new ReadableResourceStream($this->pipes[2], $loop); $this->stderr->on('close', $streamCloseHandler); // legacy PHP < 5.4 SEGFAULTs for unbuffered, non-blocking reads