Using custom handlers with output buffering #568
Replies: 2 comments 5 replies
-
Hey there! So 1. Yeah that would be an option if you wanted to handle that and probably use 3. to override the default behavior.
|
Beta Was this translation helpful? Give feedback.
-
The issue is I don't believe this would work work with either At the end, that response body is sent to the client via So that workflow could result in multiple compressed messages sent to the client which doesn't appear to be properly handled in all cases. Take this test code: <?php
use HostByBelle\CompressionBuffer;
require 'vendor/autoload.php';
CompressionBuffer::setUp();
$result = CompressionBuffer::handler('If you can read this, it works!');
$result.= CompressionBuffer::handler('I do not think this will work');
echo $result; Now somewhat to my surprise, Chrome with zstd actually does display both parts of the body: However for both Chrome and Firefox you'll only get whatever was compressed first when using I haven't tested brotli compression as I'm on my Windows PC and don't have the extension for it installed, but either way I think it's pretty fair to say for the specific use-case of compressing the output it needs to be done on the completed output before being sent rather than each individual step. For a lot of use cases, being able to directly register a handler with I can very easily set the default phase value for CompressionBuffer to The option for a final callback may also prove useful in cases like #549 |
Beta Was this translation helpful? Give feedback.
-
Hi all!
Recently I began work on CompressionBuffer to work with output buffering in PHP to allow any PHP application to have brotli and zstd output compression (and gzip too) on any webserver with it automatically selecting the best one based on the client's headers and what extensions are installed in PHP.
Using this you can get modern, insanely fast compression on even the PHP development server or for example zstd compression before either httpd or NGINX get official support for it.
I thought it would be interesting to be able to use this with apps built using Flight, but looking at the code that doesn't really seem like the case.
It could work with v2 output buffering by passing the handler here, but that's deprecated and to be removed in v4.
So to me this leaves three options:
Flight::start();
wrapped in it's own output buffer that uses CompressionBuffer.Not sure what the ideal way to go about that would be, so I'm curious on your general thoughts.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions