Skip to content

Commit 501fdc5

Browse files
authored
Merge pull request #26 from clue-labs/ext-zlib
Require ext-zlib during installation
2 parents ccec995 + a3b6535 commit 501fdc5

File tree

7 files changed

+17
-32
lines changed

7 files changed

+17
-32
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,22 @@ $ composer require clue/zlib-react:^0.2.2
248248
See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.
249249

250250
This project aims to run on any platform and thus does not require any PHP
251-
extensions and supports running on legacy PHP 5.4 through current PHP 7+.
251+
extensions besides `ext-zlib` and supports running on legacy PHP 5.4 through current
252+
PHP 7+.
252253
It's *highly recommended to use PHP 7+* for this project.
253254

254-
The `ext-zlib` extension is not required to install this library, however it
255-
is required to actually do anything meaningful with this library.
256-
Each of the above methods will throw an `Exception` if this extension is
257-
missing.
255+
The `ext-zlib` extension is required for handling the underlying data compression
256+
and decompression.
257+
This extension is already installed as part of many PHP distributions out-of-the-box,
258+
e.g. it ships with Debian/Ubuntu-based PHP installations and Windows-based
259+
builds by default. If you're building PHP from source, you may have to
260+
[manually enable](https://www.php.net/manual/en/zlib.installation.php) it.
258261

259262
We're committed to providing a smooth upgrade path for legacy setups.
260263
If you need to support legacy PHP 5.3 and legacy HHVM, you may want to check out
261264
the legacy `v0.2.x` release branch.
265+
This legacy release branch also provides an installation candidate that does not
266+
require `ext-zlib` during installation but uses runtime checks instead.
262267

263268
## Tests
264269

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
],
1313
"require": {
1414
"php": ">=5.4",
15+
"ext-zlib": "*",
1516
"clue/stream-filter": "~1.3",
1617
"react/stream": "^1.0 || ^0.7 || ^0.6"
1718
},

examples/91-benchmark-compress.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@
2222
exit(1);
2323
}
2424

25-
if (!defined('ZLIB_ENCODING_GZIP')) {
26-
fwrite(STDERR, 'Requires PHP with ext-zlib enabled' . PHP_EOL);
27-
exit(1);
28-
}
29-
30-
3125
if (extension_loaded('xdebug')) {
3226
echo 'NOTICE: The "xdebug" extension is loaded, this has a major impact on performance.' . PHP_EOL;
3327
}

examples/92-benchmark-decompress.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
exit(1);
2727
}
2828

29-
if (!defined('ZLIB_ENCODING_GZIP')) {
30-
fwrite(STDERR, 'Requires PHP with ext-zlib enabled' . PHP_EOL);
31-
exit(1);
32-
}
33-
3429
if ($argc !== 2) {
3530
fwrite(STDERR, 'No archive given, requires single argument' . PHP_EOL);
3631
exit(1);

examples/gunzip.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
exit(1);
88
}
99

10-
if (!defined('ZLIB_ENCODING_GZIP')) {
11-
fwrite(STDERR, 'Requires PHP with ext-zlib enabled' . PHP_EOL);
12-
exit(1);
13-
}
14-
1510
$loop = React\EventLoop\Factory::create();
1611

1712
$in = new React\Stream\ReadableResourceStream(STDIN, $loop);

examples/gzip.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
exit(1);
88
}
99

10-
if (!defined('ZLIB_ENCODING_GZIP')) {
11-
fwrite(STDERR, 'Requires PHP with ext-zlib enabled' . PHP_EOL);
12-
exit(1);
13-
}
14-
1510
$loop = React\EventLoop\Factory::create();
1611

1712
$in = new React\Stream\ReadableResourceStream(STDIN, $loop);

src/ZlibFilterStream.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ZlibFilterStream extends TransformStream
2424
*/
2525
public static function createGzipCompressor($level = -1)
2626
{
27-
return new Compressor(15 | 16 /* ZLIB_ENCODING_GZIP */, $level);
27+
return new Compressor(ZLIB_ENCODING_GZIP, $level);
2828
}
2929

3030
/**
@@ -33,7 +33,7 @@ public static function createGzipCompressor($level = -1)
3333
*/
3434
public static function createGzipDecompressor()
3535
{
36-
return new Decompressor(15 | 16 /* ZLIB_ENCODING_GZIP */);
36+
return new Decompressor(ZLIB_ENCODING_GZIP);
3737
}
3838

3939
/**
@@ -42,7 +42,7 @@ public static function createGzipDecompressor()
4242
*/
4343
public static function createDeflateCompressor($level = -1)
4444
{
45-
return new Compressor(-15 /* ZLIB_ENCODING_RAW */, $level);
45+
return new Compressor(ZLIB_ENCODING_RAW, $level);
4646
}
4747

4848
/**
@@ -51,7 +51,7 @@ public static function createDeflateCompressor($level = -1)
5151
*/
5252
public static function createDeflateDecompressor()
5353
{
54-
return new Decompressor(-15 /* ZLIB_ENCODING_RAW */);
54+
return new Decompressor(ZLIB_ENCODING_RAW);
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ public static function createDeflateDecompressor()
6060
*/
6161
public static function createZlibCompressor($level = -1)
6262
{
63-
return new Compressor(15 /* ZLIB_ENCODING_DEFLATE */, $level);
63+
return new Compressor(ZLIB_ENCODING_DEFLATE, $level);
6464
}
6565

6666
/**
@@ -69,7 +69,7 @@ public static function createZlibCompressor($level = -1)
6969
*/
7070
public static function createZlibDecompressor()
7171
{
72-
return new Decompressor(15 /* ZLIB_ENCODING_DEFLATE */);
72+
return new Decompressor(ZLIB_ENCODING_DEFLATE);
7373
}
7474

7575
private $filter;

0 commit comments

Comments
 (0)