【问题标题】:How to debug a Symfony StreamedResponse?如何调试 Symfony StreamedResponse?
【发布时间】:2019-04-15 10:29:09
【问题描述】:

我正在使用 StreamedResponse 来提供大型 CSV 文件。当我在 回调函数 中遇到错误时,浏览器只会显示“找不到文件”错误,并且我无法访问 Symfony 调试工具栏。有没有办法访问回调中抛出的异常? 我的操作如下所示:

  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;
  }

编辑 大多数时候,在浏览器开发工具中查看请求时,响应内容是空白的。

【问题讨论】:

    标签: php symfony stream response


    【解决方案1】:

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

    【讨论】:

    • 谢谢,可能有更方便的方法,但成功了。
    • 有时,在浏览器开发工具控制台中查看时,我什至没有获得失败请求的状态,并且它没有出现在“最后 10 个”按钮中。知道为什么吗?只收到“找不到文件”消息。
    【解决方案2】:

    注意

    网络调试工具栏不适用于类型响应 StreamedResponse.

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-21
      • 2018-05-20
      • 1970-01-01
      • 2018-12-06
      • 2015-12-12
      • 2021-10-02
      • 2018-09-18
      • 1970-01-01
      相关资源
      最近更新 更多