From 7e70eee888a9a4ec59068f869fb854b086405b32 Mon Sep 17 00:00:00 2001 From: ralf Date: Thu, 5 May 2022 12:47:31 +0200 Subject: [PATCH] final fix for "Network error" when stream files to client It is important to FIRST disable zlib.output_compression (before headers are sent!) and THEN end all output-buffering! Without the two steps in this order, we are either limited by the memory limit or get the "Network error", because the streaming/fpassthrough does not apply the compression. --- api/src/Vfs.php | 5 +++++ importexport/inc/class.importexport_export_ui.inc.php | 5 +++++ setup/db_backup.php | 10 +++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/api/src/Vfs.php b/api/src/Vfs.php index a2359cb400..deda97ed11 100644 --- a/api/src/Vfs.php +++ b/api/src/Vfs.php @@ -1504,6 +1504,11 @@ class Vfs extends Vfs\Base //error_log("Total files: " . $total_files . " Peak memory to zip: " . self::hsize(memory_get_peak_usage(true))); + // FIRST: switch off zlib.output_compression, as this would limit downloads in size to memory_limit + ini_set('zlib.output_compression',0); + // SECOND: end all active output buffering + while(ob_end_clean()) {} + // Stream the file to the client header("Content-Type: application/zip"); header("Content-Length: " . filesize($zip_file)); diff --git a/importexport/inc/class.importexport_export_ui.inc.php b/importexport/inc/class.importexport_export_ui.inc.php index 61192d66af..aa99a70f8b 100644 --- a/importexport/inc/class.importexport_export_ui.inc.php +++ b/importexport/inc/class.importexport_export_ui.inc.php @@ -446,6 +446,11 @@ class importexport_export_ui { $appname = $_GET['_appname']; $nicefname = $_GET['filename'] ? $_GET['filename'] : 'egw_export_'.$appname.'-'.date('Y-m-d'); + // FIRST: switch off zlib.output_compression, as this would limit downloads in size to memory_limit + ini_set('zlib.output_compression',0); + // SECOND: end all active output buffering + while(ob_end_clean()) {} + // Get charset $charset = Api\Cache::getSession('importexport', $tmpfname); diff --git a/setup/db_backup.php b/setup/db_backup.php index c98f29b90b..f6eca27aef 100644 --- a/setup/db_backup.php +++ b/setup/db_backup.php @@ -42,8 +42,12 @@ if (!empty($_POST['download'])) { $file = key($_POST['download']); $file = $db_backup->backup_dir.'/'.basename($file); // basename to now allow to change the dir - while (@ob_end_clean()) {} // end all active output buffering - ini_set('zlib.output_compression',0); // switch off zlib.output_compression, as this would limit downloads in size to memory_limit + + // FIRST: switch off zlib.output_compression, as this would limit downloads in size to memory_limit + ini_set('zlib.output_compression',0); + // SECOND: end all active output buffering + while(ob_end_clean()) {} + Api\Header\Content::type(basename($file)); readfile($file); exit; @@ -310,4 +314,4 @@ if ($run_in_egw) else { $GLOBALS['egw_setup']->html->show_footer(); -} +} \ No newline at end of file