1--TEST--
2compress.zlib:// wrapper with compression level
3--EXTENSIONS--
4zlib
5--SKIPIF--
6<?php in_array('compress.zlib', stream_get_wrappers()) || print 'skip No zlib wrapper';
7--FILE--
8<?php declare(strict_types=1);
9
10$filename = tempnam(sys_get_temp_dir(), "php-zlib-test-");
11$thisfile = file_get_contents(__FILE__);
12
13function write_at_level(int $level) {
14  global $filename, $thisfile;
15
16  $ctx = stream_context_create(['zlib' => ['level' => $level] ]);
17  $fp = fopen("compress.zlib://$filename", 'w', false, $ctx);
18  for ($i = 0; $i < 10; ++$i) {
19    fwrite($fp, $thisfile);
20  }
21  fclose($fp);
22  $size = filesize($filename);
23  unlink($filename);
24  return $size;
25}
26
27$size1 = write_at_level(1);
28$size9 = write_at_level(9);
29
30var_dump(10 * strlen($thisfile));
31var_dump($size1);
32var_dump($size9);
33var_dump($size9 < $size1);
34?>
35--EXPECTF--
36int(%d)
37int(%d)
38int(%d)
39bool(true)
40