简体   繁体   English

如何调试 Symfony StreamedResponse?

[英]How to debug a Symfony StreamedResponse?

I'm using a StreamedResponse to serve a large CSV file.我正在使用StreamedResponse来提供大型 CSV 文件。 When I get an error in the callback function , the browser merely displays a "file not found" error, and I have no access to the Symfony debug toolbar.当我在回调函数中遇到错误时,浏览器仅显示“找不到文件”错误,而我无法访问 Symfony 调试工具栏。 Is there a way to access the Exception that was thrown in the callback ?有没有办法访问回调中抛出的异常? My action looks like this:我的动作是这样的:

  public function exportAction(Request $request) {

     $response = new StreamedResponse();
     $response->setCallback(function() {

        // Here i'm fetching my data with Doctrine and outputting it with 
        // $handle = fopen('php://output', 'w'); ...fputcsv() ...fclose();

     });

     $response->setStatusCode(200);
     $response->headers->set('Content-Type', 'text/csv; charset=utf-8');
     $response->headers->set('Content-Disposition', 'attachment; filename="export.csv"');

     return $response;
  }

EDIT Most of the time, when looking at the request in the browser dev tool, the response content is blank.编辑大多数时候,在浏览器开发工具中查看请求时,响应内容为空白。

嗯...我不知道有什么方便的方法,但是您可以加载主页,打开分析器,然后单击“最后10个”按钮以查看过去的配置文件。

Caution警告

The web debug toolbar is not available for responses of type StreamedResponse . Web 调试工具栏不适用于StreamedResponse类型的响应。

Source: https://symfony.com/doc/current/reference/configuration/web_profiler.html来源: https : //symfony.com/doc/current/reference/configuration/web_profiler.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM