Developing software in the Real World

OuputBuffer Middleware for Expressive

When developing an Expressive application, if you use var_dump(), echo, print_r(), etc when you get this error:

This occurs after your data has been displayed and makes perfect sense as Expressive is unable to send headers as you've already started sending the body.

To solve this, you need some middleware. It looks like this:

This middleware wraps all subsequent middleware in an output buffer and then either appends or prepends the contents to the response.

To use it, add to your pipline.php:

Now, you can see the output at the same time as your debugging messages!

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *