@@ -67,7 +67,7 @@ use Slim\Psr7\Response;
6767return $zipResponder->zipFile(new Response(), 'source.zip', 'output.zip');
6868```
6969
70- In reality, you should use the Response object from the action handler:
70+ In reality, it makes sense to use the response object of the action handler:
7171
7272``` php
7373return $zipResponder->zipFile($response, 'source.zip', 'output.zip');
@@ -86,8 +86,8 @@ return $zipResponder->zipStream($response, $stream, 'output.zip');
8686### Sending a ZipStream-PHP archive
8787
8888[ ZipStream-PHP] ( https://github.com/maennchen/ZipStream-PHP ) is a library for
89- dynamically streaming dynamic zip files from PHP without writing to the disk at
90- all on the server. You can directly send it to the user, which is much faster.
89+ streaming dynamic ZIP files without writing to the disk.
90+ You can send the file directly to the user, which is much faster and improves testability .
9191
9292** Installation:**
9393
@@ -103,9 +103,11 @@ use ZipStream\ZipStream;
103103
104104// ...
105105
106+ // Create ZIP file, only in-memory
106107$archive = new Archive();
107108$archive->setOutputStream(fopen('php://memory', 'r+'));
108109
110+ // Add files to ZIP file
109111$zip = new ZipStream(null, $archive);
110112$zip->addFile('test.txt', 'my file content');
111113$zip->finish();
@@ -125,13 +127,16 @@ For this purpose, you can create a temporary file, or you can use an existing fi
125127use ZipArchive;
126128// ...
127129
130+ // Create temporary filename
128131$filename = tempnam(sys_get_temp_dir(), 'zip');
129132
133+ // Add files to temporary ZIP file
130134$zip = new ZipArchive();
131135$zip->open($filename, ZipArchive::CREATE | ZipArchive::OVERWRITE);
132136$zip->addFromString('test.txt', 'my content');
133137$zip->close();
134138
139+ // Render ZIP file into the response as stream
135140return $zipResponder->zipStream($response, fopen($filename, 'r+'), 'download.zip');
136141```
137142
@@ -147,9 +152,9 @@ return $zipResponder->deflateResponse($response);
147152
148153To make sure you’re actually serving up compressed content you can:
149154
150- In your browser: In Chrome or Firefox, open the Developer Tools (F12) > Network Tab .
151- Refresh your page, and click the network line for the page itself.
152- The header ` Content-encoding: deflate ` means the contents were sent compressed.
155+ In your browser: In Chrome or Firefox, open the Developer Toolbar (F12) > Network tab .
156+ Refresh the page, and click the network line for the page itself.
157+ The header ` Content-encoding: deflate ` means that the content was sent compressed.
153158
154159Use the [ online gzip test] ( http://www.gidnetwork.com/tools/gzip-test.php ) to check whether your page is compressed.
155160
@@ -160,7 +165,7 @@ As exciting as it may appear, HTTP Compression isn’t all fun and games. Here
160165* Older browsers: Yes, some browsers still may have trouble with compressed content
161166 (they say they can accept it, but really they can’t).
162167 If your site absolutely must work with very old browsers, you may not want to
163- use HTTP Compression .
168+ use HTTP compression .
164169
165170* Already-compressed content: Most images, music and videos are already compressed.
166171 Don’t waste time compressing them again. In fact, you probably only need to compress
@@ -173,6 +178,24 @@ As exciting as it may appear, HTTP Compression isn’t all fun and games. Here
173178 be a net win. Using CPU cycles for a faster user experience is well worth it,
174179 given the short attention spans on the web.
175180
181+ Another way to compress the HTTP content is to use the Apache ` mod_deflate ` module instead.
182+ You can restrict compression to specific MIME types if needed.
183+
184+ ``` htaccess
185+ <IfModule mod_deflate.c>
186+ AddOutputFilterByType DEFLATE text/plain
187+ AddOutputFilterByType DEFLATE text/html
188+ AddOutputFilterByType DEFLATE text/xml
189+ AddOutputFilterByType DEFLATE text/shtml
190+ AddOutputFilterByType DEFLATE text/css
191+ AddOutputFilterByType DEFLATE application/xml
192+ AddOutputFilterByType DEFLATE application/xhtml+xml
193+ AddOutputFilterByType DEFLATE application/rss+xml
194+ AddOutputFilterByType DEFLATE application/javascript
195+ AddOutputFilterByType DEFLATE application/x-javascript
196+ </IfModule>
197+ ```
198+
176199## Slim 4 Integration
177200
178201Insert a DI container definition: ` StreamFactoryInterface::class `
0 commit comments