-
-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Huge memory usage, despite using SapiStreamEmitter #14
Comments
First, for anyone reading this, you need to apply PR #233 before running this code. @sasezaki your suggestion will not work. However, may be interesting to add an "ob_end_flush" at the end of "listen" method (not ob_end_clean). In order to reduce memory usage is necessary a call to "ob_flush" after each "read" call in SapiStreamEmitter.php. However I believe this may cause performance issues in most production environments. The flush calls has a very high performance cost. And besides this, the PHP engine already regularly flushes output buffer, following "output_buffering" configuration directive. Which I believe is more appropriate because it allows the application admin to choose the best balance between resource consumption and performance. And depending of layers beyond PHP engine, the "ob_flush" may be pointless (e.g. Apache buffering when using gzip). Originally posted by @fcabralpacheco at zendframework/zend-diactoros#232 (comment) |
It has been months (literally) since I started looking for a solution. In my case, here is what did the trick - Note that I'm only using the SapiStreamEmitter: ob_end_flush();
ob_implicit_flush();
$emitter->emit($response); I'm not sure if this is really efficient, but at least it works (with large files ofc). I still need to try it in prod though.. Not taking any credit here. In fact, this is from an answer (that have some up votes) on EDIT - After some more investigation.. We can simply do this. Way more cleaner. ob_implicit_flush();
$maxBufferLevel = 0; // Stands for the maximum (and last) output buffering level to unwrap
$emitter->emit($response, $maxBufferLevel); Originally posted by @cocochepeau at zendframework/zend-diactoros#232 (comment) |
SapiEmitter no longer part of laminas-diactoros |
Huge memory usage, despite using SapiStreamEmitter
When using Zend\Diactoros\Server with
->setEmitter(new \Zend\Diactoros\Response\SapiStreamEmitter());
, it is still huge memory usage.here is reproduce code.
expected Memory Usage is
2.00 MB
,but showned Memory Usage is
16.00 MB
.I think that reason is Server::listen() calls
ob_start
,but did not clean output buffer (ob_end_clean)
Originally posted by @sasezaki at zendframework/zend-diactoros#232
The text was updated successfully, but these errors were encountered: