diff --git a/README.md b/README.md index 16457e4..5bb3252 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,7 @@ gzip file stream into an decompressor which emits decompressed data events for each individual log file chunk: ```php -$loop = React\EventLoop\Factory::create(); -$stream = new React\Stream\ReadableResourceStream(fopen('access.log.gz', 'r'), $loop); +$stream = new React\Stream\ReadableResourceStream(fopen('access.log.gz', 'r')); $decompressor = new Clue\React\Zlib\Decompressor(ZLIB_ENCODING_GZIP); $stream->pipe($decompressor); @@ -48,8 +47,6 @@ $stream->pipe($decompressor); $decompressor->on('data', function ($data) { echo $data; // chunk of decompressed log data }); - -$loop->run(); ``` See also the [examples](examples). diff --git a/composer.json b/composer.json index 9380f95..f85fdbf 100644 --- a/composer.json +++ b/composer.json @@ -13,14 +13,11 @@ "require": { "php": ">=7.0", "ext-zlib": "*", - "react/stream": "^1.0 || ^0.7 || ^0.6" + "react/stream": "^1.2" }, "require-dev": { "phpunit/phpunit": "^9.3 || ^6.5", - "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3" - }, - "suggest": { - "ext-zlib": "Requires ext-zlib extension" + "react/event-loop": "^1.2" }, "autoload": { "psr-4": { "Clue\\React\\Zlib\\": "src/" } diff --git a/examples/91-benchmark-compress.php b/examples/91-benchmark-compress.php index 6269461..2c62cb3 100644 --- a/examples/91-benchmark-compress.php +++ b/examples/91-benchmark-compress.php @@ -15,6 +15,8 @@ // // $ dd if=/dev/zero bs=1M count=1k status=progress | gzip > /dev/null +use React\EventLoop\Loop; + require __DIR__ . '/../vendor/autoload.php'; if (DIRECTORY_SEPARATOR === '\\') { @@ -26,11 +28,9 @@ echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL; } -$loop = React\EventLoop\Factory::create(); - // read 1 MiB * 1 Ki times $count = 0; -$stream = new React\Stream\ReadableResourceStream(fopen('/dev/zero', 'r'), $loop, 1024*1024); +$stream = new React\Stream\ReadableResourceStream(fopen('/dev/zero', 'r'), null, 1024*1024); $stream->on('data', function () use (&$count, $stream) { if (++$count > 1024) { $stream->close(); @@ -47,17 +47,15 @@ }); // report progress periodically -$timer = $loop->addPeriodicTimer(0.05, function () use (&$bytes) { +$timer = Loop::addPeriodicTimer(0.05, function () use (&$bytes) { echo "\rCompressed $bytes bytes…"; }); // report results once the stream closes $start = microtime(true); -$stream->on('close', function () use (&$bytes, $start, $loop, $timer) { +$stream->on('close', function () use (&$bytes, $start, $timer) { $time = microtime(true) - $start; - $loop->cancelTimer($timer); + Loop::cancelTimer($timer); echo "\rCompressed $bytes bytes in " . round($time, 1) . 's => ' . round($bytes / $time / 1000000, 1) . ' MB/s' . PHP_EOL; }); - -$loop->run(); diff --git a/examples/92-benchmark-decompress.php b/examples/92-benchmark-decompress.php index 9307a11..cc78785 100644 --- a/examples/92-benchmark-decompress.php +++ b/examples/92-benchmark-decompress.php @@ -19,6 +19,8 @@ // // $ php examples/gunzip.php < null.gz | dd of=/dev/zero status=progress +use React\EventLoop\Loop; + require __DIR__ . '/../vendor/autoload.php'; if (DIRECTORY_SEPARATOR === '\\') { @@ -35,9 +37,7 @@ echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL; } -$loop = React\EventLoop\Factory::create(); - -$in = new React\Stream\ReadableResourceStream(fopen($argv[1], 'r'), $loop); +$in = new React\Stream\ReadableResourceStream(fopen($argv[1], 'r')); $stream = new Clue\React\Zlib\Decompressor(ZLIB_ENCODING_GZIP); $in->pipe($stream); @@ -49,17 +49,15 @@ $stream->on('error', 'printf'); //report progress periodically -$timer = $loop->addPeriodicTimer(0.2, function () use (&$bytes) { +$timer = Loop::addPeriodicTimer(0.2, function () use (&$bytes) { echo "\rDecompressed $bytes bytes…"; }); // show stats when stream ends $start = microtime(true); -$stream->on('close', function () use (&$bytes, $start, $loop, $timer) { +$stream->on('close', function () use (&$bytes, $start, $timer) { $time = microtime(true) - $start; - $loop->cancelTimer($timer); + Loop::cancelTimer($timer); echo "\rDecompressed $bytes bytes in " . round($time, 1) . 's => ' . round($bytes / $time / 1000000, 1) . ' MB/s' . PHP_EOL; }); - -$loop->run(); diff --git a/examples/gunzip.php b/examples/gunzip.php index 203b3ce..e400daf 100644 --- a/examples/gunzip.php +++ b/examples/gunzip.php @@ -7,10 +7,8 @@ exit(1); } -$loop = React\EventLoop\Factory::create(); - -$in = new React\Stream\ReadableResourceStream(STDIN, $loop); -$out = new React\Stream\WritableResourceStream(STDOUT, $loop); +$in = new React\Stream\ReadableResourceStream(STDIN); +$out = new React\Stream\WritableResourceStream(STDOUT); $decompressor = new Clue\React\Zlib\Decompressor(ZLIB_ENCODING_GZIP); $in->pipe($decompressor)->pipe($out); @@ -18,5 +16,3 @@ $decompressor->on('error', function ($e) { fwrite(STDERR, 'Error: ' . $e->getMessage() . PHP_EOL); }); - -$loop->run(); diff --git a/examples/gzip.php b/examples/gzip.php index 5aba965..7b9bdda 100644 --- a/examples/gzip.php +++ b/examples/gzip.php @@ -7,12 +7,8 @@ exit(1); } -$loop = React\EventLoop\Factory::create(); - -$in = new React\Stream\ReadableResourceStream(STDIN, $loop); -$out = new React\Stream\WritableResourceStream(STDOUT, $loop); +$in = new React\Stream\ReadableResourceStream(STDIN); +$out = new React\Stream\WritableResourceStream(STDOUT); $compressor = new Clue\React\Zlib\Compressor(ZLIB_ENCODING_GZIP); $in->pipe($compressor)->pipe($out); - -$loop->run();