@@ -780,6 +780,14 @@ creating a stream instance.
780
780
However, if you are writing a lower-level component or want to create a stream
781
781
instance from a stream resource, then the following chapter is for you.
782
782
783
+ > Note that the following examples use ` fopen() ` and ` stream_socket_client() `
784
+ for illustration purposes only.
785
+ These functions SHOULD NOT be used in a truly async program because each call
786
+ may take several seconds to complete and would block the EventLoop otherwise.
787
+ Additionally, the ` fopen() ` call will return a file handle on some platforms
788
+ which may or may not be supported by all EventLoop implementations.
789
+ As an alternative, you may want to use higher-level libraries listed above.
790
+
783
791
### ReadableResourceStream
784
792
785
793
The ` ReadableResourceStream ` is a concrete implementation of the
@@ -1064,17 +1072,27 @@ $through->write(2);
1064
1072
```
1065
1073
1066
1074
## Usage
1075
+
1076
+ The following example can be used to pipe the contents of a source file into
1077
+ a destination file without having to ever read the whole file into memory:
1078
+
1067
1079
``` php
1068
- $loop = React\EventLoop\Factory ::create();
1080
+ $loop = new React\EventLoop\StreamSelectLoop ::create();
1069
1081
1070
- $source = new React\Stream\ReadableResourceStream(fopen('omg .txt', 'r'), $loop);
1071
- $dest = new React\Stream\WritableResourceStream(fopen('wtf .txt', 'w'), $loop);
1082
+ $source = new React\Stream\ReadableResourceStream(fopen('source .txt', 'r'), $loop);
1083
+ $dest = new React\Stream\WritableResourceStream(fopen('destination .txt', 'w'), $loop);
1072
1084
1073
- $source->pipe($dest);
1085
+ $source->pipe($dest);
1074
1086
1075
- $loop->run();
1087
+ $loop->run();
1076
1088
```
1077
1089
1090
+ > Note that this example uses ` fopen() ` for illustration purposes only.
1091
+ This should not be used in a truly async program because the filesystem is
1092
+ inherently blocking and each call could potentially take several seconds.
1093
+ See also [ creating streams] ( #creating-streams ) for more sophisticated
1094
+ examples.
1095
+
1078
1096
## Install
1079
1097
1080
1098
The recommended way to install this library is [ through Composer] ( http://getcomposer.org ) .
0 commit comments