diff --git a/lib/accel_file.php b/lib/accel_file.php new file mode 100644 index 0000000..c938649 --- /dev/null +++ b/lib/accel_file.php @@ -0,0 +1,27 @@ +dataroot_xaccelredirect" != "") { + $newcontentpath = str_replace($CFG->dataroot, + $CFG->dataroot_xaccelredirect, $contentpath); + } + } else { + if ("$CFG->dirroot_xaccelredirect" != "") { + $newcontentpath = str_replace($CFG->dirroot, + $CFG->dirroot_xaccelredirect, $contentpath); + } + } + + if ($newcontentpath == '' ) { + readfile($contentpath); + } else { + header('X-Accel-Redirect: ' . $newcontentpath); + } +} + +?> diff --git a/lib/filelib.php b/lib/filelib.php index 1c3ddf3..a2f836d 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -33,6 +33,7 @@ require_once("$CFG->libdir/filestorage/file_exceptions.php"); require_once("$CFG->libdir/filestorage/file_storage.php"); require_once("$CFG->libdir/filestorage/zip_packer.php"); require_once("$CFG->libdir/filebrowser/file_browser.php"); +require_once("$CFG->libdir/accel_file.php"); /** * Encodes file serving url @@ -1590,12 +1591,14 @@ function prepare_file_content_sending() { } // flush and close all buffers if possible - while(ob_get_level()) { + + /*while(ob_get_level()) { if (!ob_end_flush()) { // prevent infinite loop when buffer can not be closed break; } } + */ error_reporting($olddebug); @@ -1656,7 +1659,7 @@ function send_temp_file($path, $filename, $pathisstring=false) { if ($pathisstring) { echo $path; } else { - @readfile($path); + readfile_accel($path); } die; //no more chars to output @@ -1841,7 +1844,11 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss if ($pathisstring) { echo $path; } else { - @readfile($path); + if ($dontdie) { + @readfile($path); + } else { + readfile_accel($path); + } } } else { // Try to put the file through filters @@ -1893,7 +1900,11 @@ function send_file($path, $filename, $lifetime = 'default' , $filter=0, $pathiss if ($pathisstring) { echo $path; }else { - @readfile($path); + if ($dontdie) { + @readfile($path); + } else { + readfile_accel($path); + } } } } diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index 212179c..2a3a948 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/filestorage/stored_file.php"); +require_once("$CFG->libdir/accel_file.php"); /** * Class representing local files stored in a sha1 file pool. @@ -143,7 +144,11 @@ class stored_file { throw new file_exception('storedfilecannotread', '', $path); } } - readfile($path); + + readfile_accel($path); + + //die; + //readfile($path); } /** diff --git a/theme/image.php b/theme/image.php index 63acfaf..e4aab7a 100644 --- a/theme/image.php +++ b/theme/image.php @@ -31,6 +31,7 @@ define('NO_DEBUG_DISPLAY', true); // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php +require('../lib/accel_file.php'); $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); $component = min_optional_param('component', 'moodle', 'SAFEDIR'); @@ -156,7 +157,7 @@ function send_cached_image($imagepath, $rev) { // no need to gzip already compressed images ;-) - readfile($imagepath); + readfile_accel($imagepath); die; } diff --git a/theme/javascript.php b/theme/javascript.php index 3ebba8b..31f1206 100644 --- a/theme/javascript.php +++ b/theme/javascript.php @@ -31,6 +31,7 @@ define('NO_DEBUG_DISPLAY', true); // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php +require('../lib/accel_file.php'); $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); $rev = min_optional_param('rev', 0, 'INT'); @@ -112,7 +113,7 @@ function send_cached_js($jspath) { header('Content-Length: '.filesize($jspath)); } - readfile($jspath); + readfile_accel($jspath); die; } diff --git a/theme/styles.php b/theme/styles.php index 67385e3..7f93f8d 100644 --- a/theme/styles.php +++ b/theme/styles.php @@ -31,6 +31,7 @@ define('NO_DEBUG_DISPLAY', true); // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php +require('../lib/accel_file.php'); // this stops immediately at the beginning of lib/setup.php $themename = min_optional_param('theme', 'standard', 'SAFEDIR'); $type = min_optional_param('type', 'all', 'SAFEDIR'); @@ -165,7 +166,7 @@ function send_cached_css($csspath, $rev) { header('Content-Length: '.filesize($csspath)); } - readfile($csspath); + readfile_accel($csspath); die; } diff --git a/theme/yui_image.php b/theme/yui_image.php index 23ac987..94a975c 100644 --- a/theme/yui_image.php +++ b/theme/yui_image.php @@ -27,6 +27,7 @@ // we need just the values from config.php and minlib.php define('ABORT_AFTER_CONFIG', true); require('../config.php'); // this stops immediately at the beginning of lib/setup.php +require('../lib/accel_file.php'); // this stops immediately at the beginning of lib/setup.php $path = min_optional_param('file', '', 'SAFEPATH'); @@ -90,7 +91,7 @@ function yui_image_cached($imagepath) { // no need to gzip already compressed images ;-) - readfile($imagepath); + readfile_accel($imagepath); die; }