Example #1
0
 static function controlPreprocessingOutput()
 {
     $output_cache_content = false;
     if ($output_cache = self::getOutputCacheObject()) {
         $cache_id = md5(PUBWICH_URL) . '.output';
         $output_valid_cache_content = $output_cache->get($cache_id);
         if ($output_valid_cache_content) {
             $output_cache_content = $output_valid_cache_content;
             PubwichLog::log(1, Pubwich::_("Use valid output cache content."));
             self::$disableOutput = true;
         } elseif (ENABLE_INVALID_CACHE === true) {
             // enabling alltime cache by setting lifetime unreachable high
             $output_cache->setLifeTime(time() + 666);
             PubwichLog::log(1, Pubwich::_("Use invalid output cache content."));
             $output_cache_content = $output_cache->get($cache_id);
         }
     }
     if ($output_cache_content) {
         /*
             enabling of post output processing (experimental but it seems to work properly)
             why: aggregating feeds and linked data is a performance issue
                  because the app needs to wait for a response to all the
                  http requests. To overcome this problem we could echo an
                  (old) output cache and process then the data aggregation to
                  create an updated cache for the next request.
             @see http://www.brandonchecketts.com/archives/performing-post-output-script-processing-in-php
             @see http://de2.php.net/manual/en/features.connection-handling.php#93441
         */
         ob_end_clean();
         header("Connection: close");
         header("Content-Encoding: none");
         header('Content-Type: text/html; charset=UTF-8');
         ignore_user_abort(true);
         // optional
         ob_start();
         echo $output_cache_content;
         $size = ob_get_length();
         header("Content-Length: {$size}");
         ob_end_flush();
         // Strange behaviour, will not work
         flush();
         // Unless both are called !
         @ob_end_clean();
         //do post output processing here
         PubwichLog::log(1, Pubwich::_('Start post output processing.'));
     }
     return;
 }