Skip to content

Commit

Permalink
Update react/stream to support 0.6, 0.7, and 1.x
Browse files Browse the repository at this point in the history
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 #38 (comment)

Use interfaces instead of concrete classes in the documentation #38 (comment)

Line folding
  • Loading branch information
WyriHaximus committed Jun 17, 2017
1 parent b81d06d commit 4ef64e9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions examples/11-benchmark-read.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
3 changes: 1 addition & 2 deletions examples/12-benchmark-write.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions examples/13-benchmark-throughput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4ef64e9

Please sign in to comment.