File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 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+
314require __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 ' ;
Original file line number Diff line number Diff line change 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+
311use React \EventLoop \Factory ;
412use React \Stream \ReadableResourceStream ;
513use React \Stream \WritableResourceStream ;
614
715require __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 );
You can’t perform that action at this time.
0 commit comments