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