nullpunkt/lz-string-php
LZ-string compression and decompression for PHP, letting you store and share compressed strings in URLs or localStorage with full compatibility with the JavaScript lz-string library.
lz-string by pieroxy), and re-implementing its UTF-16 + base64 quirks in PHP is a multi-day task with high regression risk. Using this package turns that into a composer require and a thin wrapper. Decision: buy/adopt, but wrap it behind your own CompressorInterface so it is a one-line swap later.localStorage payloads to the server for persistence, and fitting session/consent/feature-flag blobs inside the ~4KB cookie budget. If a roadmap item reads "let users share this view" or "sync offline drafts," this is a credible enabling dependency.Content-Encoding: gzip), storage layer (gzcompress), or payload level (LZ-String, because the browser must decompress it in JS). The package is only the third case. Making that distinction explicit prevents engineering from reaching for it as general-purpose compression.Adopt when all of these hold:
lz-string — the value is entirely in format compatibility; without a JS counterpart, there is no reason to use this over PHP's built-in gzcompress/gzdeflate.localStorage.zlib config, no Brotli negotiation, no server-side state.Look elsewhere when:
gzcompress / gzdeflate / gzencode — faster, better ratio, maintained by PHP core. This is the single most common misapplication.To executives (30 seconds): This is a small, free utility that lets our PHP backend and our JavaScript frontend speak the same compressed-string format. It's what makes "share this view as a link" and "sync browser drafts to the server" cheap to build instead of a custom format we'd have to invent and maintain forever. Cost is a composer require and roughly a day of integration and tests. It is not a strategic dependency and carries no vendor cost or lock-in — we wrap it so it can be replaced in an afternoon.
To engineering (the honest version): It's a PHP port of lz-string, so the only real justification is wire-format parity with the JS library — don't use it for general compression. It's ~111 stars, unmaintained since mid-2021, and the repo isn't inspectable, so we pin/vendor it and own the risk. Integration requirements: put it behind a Compressor interface; treat all compressed input as untrusted and enforce a max decompressed size; add round-trip tests against the JS implementation's output as fixtures, not just PHP-to-PHP; use compressToEncodedURIComponent (not raw base64) for anything URL-bound; and verify no deprecation warnings on our target PHP version before we ship. If any of those can't be met, we implement the algorithm ourselves or drop the feature — the package is a convenience, not a commitment.
How can I help you explore Laravel packages today?