diff --git a/README.md b/README.md index 21632b17..5bc84502 100644 --- a/README.md +++ b/README.md @@ -343,10 +343,18 @@ you can use any of its events and methods as usual: ```php $connection->on('data', function ($chunk) { - echo $data; + echo $chunk; }); -$conenction->on('close', function () { +$connection->on('end', function () { + echo 'ended'; +}); + +$connection->on('error', function (Exception $e) { + echo 'error: ' . $e->getMessage(); +}); + +$connection->on('close', function () { echo 'closed'; }); diff --git a/composer.json b/composer.json index de622bbc..a5f77454 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.4.5", + "react/stream": "^0.6 || ^0.5 || ^0.4.5", "react/promise": "^2.0 || ^1.1" }, "require-dev": { diff --git a/src/ConnectionInterface.php b/src/ConnectionInterface.php index d13177c5..af107530 100644 --- a/src/ConnectionInterface.php +++ b/src/ConnectionInterface.php @@ -20,7 +20,33 @@ * use React's SocketClient component instead. * * Because the `ConnectionInterface` implements the underlying - * `DuplexStreamInterface` you can use any of its events and methods as usual. + * `DuplexStreamInterface` you can use any of its events and methods as usual: + * + * ```php + * $connection->on('data', function ($chunk) { + * echo $chunk; + * }); + * + * $connection->on('end', function () { + * echo 'ended'; + * }); + * + * $connection->on('error', function (Exception $e) { + * echo 'error: ' . $e->getMessage(); + * }); + * + * $connection->on('close', function () { + * echo 'closed'; + * }); + * + * $connection->write($data); + * $connection->end($data = null); + * $connection->close(); + * // … + * ``` + * + * For more details, see the + * [`DuplexStreamInterface`](https://github.com/reactphp/stream#duplexstreaminterface). * * @see DuplexStreamInterface */