Skip to content

Commit 195515b

Browse files
committed
Add documentation for examples
1 parent bbf5938 commit 195515b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

examples/benchmark-throughput.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
<?php
22

3+
// Benchmark to measure throughput performance piping an input stream to an output stream.
4+
// This allows you to get an idea of how fast stream processing with PHP can be
5+
// and also to play around with differnt types of input and output streams.
6+
//
7+
// This example accepts a number of parameters to control the timeout (-t 1),
8+
// the input file (-i /dev/zero) and the output file (-o /dev/null).
9+
//
10+
// $ php examples/benchmark-throughput.php
11+
// $ php examples/benchmark-throughput.php -t 10 -o zero.bin
12+
// $ php examples/benchmark-throughput.php -t 60 -i zero.bin
13+
314
require __DIR__ . '/../vendor/autoload.php';
415

16+
if (DIRECTORY_SEPARATOR === '\\') {
17+
fwrite(STDERR, 'Non-blocking console I/O not supported on Microsoft Windows' . PHP_EOL);
18+
exit(1);
19+
}
20+
521
$args = getopt('i:o:t:');
622
$if = isset($args['i']) ? $args['i'] : '/dev/zero';
723
$of = isset($args['o']) ? $args['o'] : '/dev/null';

examples/cat.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
<?php
22

3+
// Simple example piping everything from STDIN to STDOUT.
4+
// This allows you to output everything you type on your keyboard or to redirect
5+
// the pipes to show contents of files and other streams.
6+
//
7+
// $ php examples/cat.php
8+
// $ php examples/cat.php < README.md
9+
// $ echo hello | php examples/cat.php
10+
311
use React\EventLoop\Factory;
412
use React\Stream\ReadableResourceStream;
513
use React\Stream\WritableResourceStream;
614

715
require __DIR__ . '/../vendor/autoload.php';
816

17+
if (DIRECTORY_SEPARATOR === '\\') {
18+
fwrite(STDERR, 'Non-blocking console I/O not supported on Microsoft Windows' . PHP_EOL);
19+
exit(1);
20+
}
21+
922
$loop = Factory::create();
1023

1124
$stdout = new WritableResourceStream(STDOUT, $loop);

0 commit comments

Comments
 (0)