Response returned only after kernel.terminate event Response returned only after kernel.terminate event symfony symfony

Response returned only after kernel.terminate event


This issue turned out to be very specific to my setup (Nginx, PHP-FCGI, Symfony).

There were a handful of issues in play that caused the issue:

  1. Symfony does not include a Content-Length nor Connection: close header
  2. PHP-FCGI does not support the fastcgi_finish_request function
  3. Nginx buffers the response from PHP-FCGI because Gzip is on

The solution was to switch from PHP-FCGI to PHP-FPM in order to get support for fastcgi_finish_request. Symfony internally calls this before executing the kernel terminate logic thereby definitively closing the connection.

Another way to solve this would be to turn off Gzip on Nginx, but this wasn't really an option for me.