From b09d4f638c6e15894ac5ff29f94e74f9db665fce Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Tue, 16 Jul 2013 21:38:07 +0200 Subject: [PATCH] Sends PHP packaged archives in smaller segments (16MB) to not hit PHP's memory limit. Thanks to Zaoh Lei. --- src/_h5ai/conf/options.json | 2 +- src/_h5ai/server/php/inc/Api.php | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index deb35704..fc70051b 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -105,7 +105,7 @@ Options */ "download": { "enabled": true, - "execution": "shell", + "execution": "php", "format": "tar", "packageName": null }, diff --git a/src/_h5ai/server/php/inc/Api.php b/src/_h5ai/server/php/inc/Api.php index 63a3ed7d..327f3ef9 100644 --- a/src/_h5ai/server/php/inc/Api.php +++ b/src/_h5ai/server/php/inc/Api.php @@ -136,21 +136,18 @@ class Api { header("Connection: close"); register_shutdown_function("delete_tempfile", $target); - readfile($target); + // readfile($target); - // Patch by Zhao Lei - // Max size of download file is limited by memory_limit(default: 128M) - // in php.ini if we use readfile(). - // To solve this problem, we can change to send data with small segments. - // if ($fd = fopen($target, 'rb')) { - // set_time_limit(0); - // while (!feof($fd)) { - // print fread($fd, 1024 * 64); - // ob_flush(); - // flush(); - // } - // fclose($fd); - // } + // Send data in small segments of 16MB to not hit PHP's memory limit (default: 128M) + if ($fd = fopen($target, 'rb')) { + set_time_limit(0); + while (!feof($fd)) { + print fread($fd, 1024 * 1024 * 16); + ob_flush(); + flush(); + } + fclose($fd); + } }