Open jab4 opened 3 months ago
I'm quite happy chromium browsers now announce that they accept zstd. It's far faster than either gzip or brotli.
Of course, based on my own testing brotli
is still a great upgrade over gzip
both in terms of speed and compression ratio, but zstd
offers very similar compression ratios to brotli
while being significantly faster which makes it the clear winner in all cases in my eyes.
I've actually gone ahead and created my own replacement for PHP's ob_gzhandler
function which is able to auto select between zstd
, brotli
, gzip
, and deflate
content encoding based on the server it's running on and the client that's connecting to it.
https://github.com/HostByBelle/CompressionBuffer
Here's the PHP developer server sending zstd compressed output to chrome:
I haven't yet made a release of CompressionBuffer as it's only had minimal testing done plus no unit tests written, but the logic behind it is pretty straightforward and PHPStan is happy on it's highest level.
Although it's not super important for just an example, I personally include it over the above code example as that one is what I would consider incomplete. At the very least it would probably be worth mentioning that false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'zstd')
will also trigger if the client is trying to inform the server to not use zstd encoding, along with suggesting that Vary: Accept-Encoding
be sent in the headers for caching compatibility.
Either way, thank you @kjdev for building both this and the brotli extension! They are great additions to the PHP ecosystem. I for one am exciting knowing that some clever handling of the output buffer means PHP apps can utilize zstd compression before either NGINX or Apache get official support for it. Awesome!
Thanks @BelleNottelling, much appreciated!
You're welcome @jab4!
Feel free to submit issues if you come across any issues & notice potential improvements.
Hope it comes in handy :)
Hi and late Happy Easter all!
As the title suggests, no issue in the buggy sense.
I ran some benchmarks against a 4 MB HTML file:
Kindly suggest updating your README's example section to include output buffering:
Perhaps @remicollet could put some soft pressure on the PHP core team to bundle this extension? 🚀
Thanks!