Commit 740bfacf by Scott

Add output buffering to AJAX requests

Fixes #443.
Extract output buffering to function.
Use regular buffering if gzip option not set.
Use buffering in AJAX requests, to avoid “headers already sent” warning
in some situations.
parent 4f6d7f0c
......@@ -80,6 +80,7 @@
if (isset($routing[$operation])) {
qa_db_connect('qa_ajax_db_fail_handler');
qa_initialize_buffering();
require QA_INCLUDE_DIR.'ajax/'.$routing[$operation];
qa_db_disconnect();
......
......@@ -319,6 +319,23 @@
}
/**
* Set up output buffering. Use gzip compression if option set and it's not an admin page (since some of these contain lengthy processes).
* @param $request
* @return bool whether buffering was used
*/
function qa_initialize_buffering($request='')
{
if (headers_sent()) {
return false;
}
$useGzip = QA_HTML_COMPRESSION && substr($request, 0, 6) !== 'admin/' && extension_loaded('zlib');
ob_start($useGzip ? 'ob_gzhandler' : null);
return true;
}
function qa_register_core_modules()
/*
Register all modules that come as part of the Q2A core (as opposed to plugins)
......
......@@ -182,11 +182,7 @@
require QA_INCLUDE_DIR.'qa-url-test.php';
else {
// enable gzip compression for output (needs to come early)
// skip admin pages since some of these contain lengthy processes
if (QA_HTML_COMPRESSION && substr($requestlower, 0, 6) != 'admin/') {
if (extension_loaded('zlib') && !headers_sent())
ob_start('ob_gzhandler');
}
qa_initialize_buffering($requestlower);
if (substr($requestlower, 0, 5) == 'feed/')
require QA_INCLUDE_DIR.'qa-feed.php';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment