关于使用压缩函数以块写入 gzip 编码文件的示例。
<?php
$handler = fopen('/tmp/test.csv', 'w');
$deflateContext = deflate_init(ZLIB_ENCODING_GZIP, ['level' => 9]);
$strings = [
'Hello, how are you?' . PHP_EOL,
'I am fine thanks' . PHP_EOL,
'Hello, how are you?' . PHP_EOL,
];
foreach ($strings as $string) {
fwrite($handler, deflate_add($deflateContext, $string, ZLIB_NO_FLUSH));
}
fwrite($handler, deflate_add($deflateContext, '', ZLIB_FINISH));
fclose($handler);
echo gzdecode(file_get_contents('/tmp/test.csv'));