Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Zipstream Php

Zipstream Php Laravel Package

maennchen/zipstream-php

Stream ZIP archives on the fly in PHP without writing to disk. Fast ZIP downloads with optional HTTP headers, supports adding files from strings/paths, works with S3 and PSR-7 streams, and can output to custom callbacks.

View on GitHub
Deep Wiki
Context7

ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.

Frequently asked questions about Zipstream Php
How do I integrate ZipStream-PHP into a Laravel controller to send a ZIP download directly to the browser?
Use Laravel’s `Response` class with `streamDownload()`. Initialize `ZipStream`, add files, then pass the stream to `Response::stream()`. Example: `$response = Response::streamDownload(fn() => $zip->getStream(), 'export.zip');` Ensure `sendHttpHeaders: true` in `ZipStream` for proper browser handling.
Can ZipStream-PHP handle large files (e.g., 1GB+) without memory issues?
Yes, it streams files directly without buffering the entire ZIP in memory. For files >4GB, Zip64 is auto-enabled, but test directory structures >4GB (fixed in v3.2.2). Monitor memory usage with `memory_get_usage()` if processing edge cases.
Does ZipStream-PHP work with Laravel 9.x or only Laravel 10+?
ZipStream-PHP requires PHP 8.2+, which aligns with Laravel 10+. For Laravel 9.x (PHP 8.1), use a fork like `maennchen/zipstream-php:dev` or polyfill missing features. Test thoroughly for compatibility.
How can I stream a ZIP directly to AWS S3 instead of the browser?
Use `S3StreamWrapper` from the package. Initialize `ZipStream` with `outputStream: S3StreamWrapper::open($s3Client, 'bucket', 'file.zip')` and set `sendHttpHeaders: false`. The ZIP will stream directly to S3 without temporary files.
What’s the best way to add dynamic content (e.g., database-generated files) to a ZIP?
Use `addFile()` with string data or `addFileFromPath()` for filesystem files. For dynamic content, generate files in memory (e.g., PDFs via Dompdf) and pass the binary string. Example: `$zip->addFile('report.pdf', $pdf->output());`
How do I handle errors if the ZIP stream fails (e.g., S3 upload errors)?
Wrap `ZipStream` in a try-catch block. For partial failures, log errors and either abort the stream (throw an exception) or save the partial ZIP to a fallback location. Use Laravel’s `Log::error()` for debugging.
Is ZipStream-PHP compatible with Laravel’s queue system for background ZIP generation?
Yes. Dispatch a job (e.g., `HandleZipExportJob`) that generates the ZIP, then stream it to the user upon job completion. Use `Response::streamDownload()` in the job’s handle method or store the ZIP in S3 and send a download link.
Can I add progress tracking for large ZIP downloads in the browser?
Yes. Use `Content-Length` headers to enable progress bars. For Nginx, add `X-Accel-Buffering: no` to the response. Alternatively, implement client-side polling with a `progress` endpoint that tracks streamed bytes.
What are the alternatives to ZipStream-PHP for Laravel ZIP generation?
For small ZIPs (<100MB), Laravel’s built-in `ZipArchive` suffices. For S3-heavy workflows, combine `spatie/laravel-activitylog` with S3 events. ZipStream-PHP excels for large, dynamic, or streaming use cases due to its memory efficiency.
How do I test ZipStream-PHP in a Laravel application before production?
Test with small ZIPs first (e.g., 10–50MB) to verify streaming. Use Laravel’s `Http::fake()` to mock responses, then scale to larger files. Validate S3 streams with `Storage::fake('s3')` and check for edge cases like 100K+ files or Unicode filenames.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai