【发布时间】: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