Index: branches/RC/core/units/general/helpers/sections_helper.php
===================================================================
diff -u -r9776 -r10580
--- branches/RC/core/units/general/helpers/sections_helper.php (.../sections_helper.php) (revision 9776)
+++ branches/RC/core/units/general/helpers/sections_helper.php (.../sections_helper.php) (revision 10580)
@@ -33,9 +33,11 @@
*/
function BuildTree()
{
- $data = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"');
+ if (!isset($this->Application->Memcached) || !($data = $this->Application->Memcached->get('master:sections_parsed'))) {
+ $data = $this->Conn->GetOne('SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"');
+ }
if ($data) {
- $this->Tree = unserialize($data['Data']);
+ $this->Tree = unserialize($data);
return ;
}
@@ -141,6 +143,11 @@
}
$this->Application->HandleEvent( new kEvent('adm:OnAfterBuildTree') );
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->set('master:sections_parsed',serialize($this->Tree), 0, 0);
+ return;
+ }
+
$this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("sections_parsed", '.$this->Conn->qstr(serialize($this->Tree)).', '.adodb_mktime().')');
}
Index: branches/RC/core/units/themes/themes_config.php
===================================================================
diff -u -r9618 -r10580
--- branches/RC/core/units/themes/themes_config.php (.../themes_config.php) (revision 9618)
+++ branches/RC/core/units/themes/themes_config.php (.../themes_config.php) (revision 10580)
@@ -2,7 +2,7 @@
$config = Array(
'Prefix' => 'theme',
- 'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
+ 'ItemClass' => Array('class'=>'ThemeItem','file'=>'theme_item.php','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'ThemesEventHandler','file'=>'themes_eh.php','build_event'=>'OnBuild'),
'TagProcessorClass' => Array('class'=>'ThemesTagProcessor','file'=>'themes_tag_processor.php','build_event'=>'OnBuild'),
Index: branches/RC/core/units/admin/admin_events_handler.php
===================================================================
diff -u -r10577 -r10580
--- branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10577)
+++ branches/RC/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 10580)
@@ -66,6 +66,9 @@
$event->status = erSTOP;
}
$this->Conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"');
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->delete('master:sections_parsed');
+ }
}
function OnResetConfigsCache(&$event)
@@ -74,6 +77,11 @@
$event->status = erSTOP;
}
$this->Conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files" OR VarName = "configs_parsed" OR VarName = "sections_parsed"');
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->delete('master:config_files');
+ $this->Application->Memcached->delete('master:configs_parsed');
+ $this->Application->Memcached->delete('master:sections_parsed');
+ }
}
function OnCompileTemplates(&$event)
Index: branches/RC/core/units/general/inp_ses_storage.php
===================================================================
diff -u -r10294 -r10580
--- branches/RC/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 10294)
+++ branches/RC/core/units/general/inp_ses_storage.php (.../inp_ses_storage.php) (revision 10580)
@@ -47,7 +47,7 @@
{
$this->Storage->DeleteSession($this);
$this->Storage->DeleteEditTables();
- $this->Data =& new Params();
+ $this->Data = new Params();
$this->SID = '';
if ($this->CookiesEnabled) $this->SetSessionCookie(); //will remove the cookie due to value (sid) is empty
$this->SetSession(); //will create a new session
Index: branches/RC/core/kernel/languages/phrases_cache.php
===================================================================
diff -u -r10098 -r10580
--- branches/RC/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 10098)
+++ branches/RC/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 10580)
@@ -17,7 +17,7 @@
var $LanguageId = null;
var $fromTag = false;
-
+
function PhrasesCache()
{
parent::kBase();
@@ -115,6 +115,10 @@
function GetPhrase($label)
{
+ if (!isset($this->LanguageId)) return 'impossible case';
+ //actually possible when custom field contains references to language labels and its being rebuilt in OnAfterConfigRead
+ //which is triggered by Sections rebuild, which in turn read all the configs and all of that happens BEFORE seeting the language...
+
if (ereg("^!.+!$", $label) > 0)
{
$label = substr($label, 1, -1); //cut exclamation marks
Index: branches/RC/core/kernel/utility/debugger.php
===================================================================
diff -u -r10577 -r10580
--- branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10577)
+++ branches/RC/core/kernel/utility/debugger.php (.../debugger.php) (revision 10580)
@@ -80,6 +80,14 @@
* @var string
*/
var $baseURL = '';
+
+
+ /**
+ * Holds last recorded timestamp (for appendTimestamp)
+ *
+ * @var int
+ */
+ var $LastMoment;
function Debugger()
{
@@ -101,6 +109,7 @@
$this->InitDebugger();
$this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4', $start);
$this->profileStart('script_runtime', 'Script runtime', $start);
+ $this->LastMoment = $start;
error_reporting(E_ALL);
ini_set('display_errors', $this->constOn('DBG_ZEND_PRESENT') ? 0 : 1); // show errors on screen in case if not in Zend Studio debugging
@@ -260,6 +269,7 @@
// string used to separate debugger records while in file (used in debugger dump filename too)
$this->rowSeparator = '@'.(is_object($application->Factory) ? $application->GetSID() : 0).'@';
+// $this->rowSeparator = '@'.rand(0,100000).'@';
// include debugger files from this url
$reg_exp = '/^'.preg_quote(FULL_PATH, '/').'/';
@@ -887,6 +897,16 @@
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
+
+ function appendTimestamp($message)
+ {
+ global $start;
+ $time = $this->getMoment();
+ $from_last = $time - $this->LastMoment;
+ $from_start = $time - $start;
+ $this->appendHTML(sprintf("%s %.5f from last %.5f from start", $message, $from_last, $from_start));
+ $this->LastMoment = $time;
+ }
function generateID()
{
@@ -1040,7 +1060,7 @@
}
}
- /*if ($this->constOn('DBG_PROFILE_INCLUDES')) {
+ if ($this->constOn('DBG_PROFILE_INCLUDES')) {
$this->appendHTML('Included files statistics:'.( $this->constOn('DBG_SORT_INCLUDES_MEM') ? ' (sorted by memory usage)':''));
$totals = Array( 'mem' => 0, 'time' => 0);
$totals_configs = Array( 'mem' => 0, 'time' => 0);
@@ -1063,7 +1083,7 @@
$this->appendHTML('Sub-Total configs: '.' Mem: '.sprintf("%.4f Kb", $totals_configs['mem']/1024).' Time: '.sprintf("%.4f", $totals_configs['time']));
$this->appendHTML('Grand Total: '.' Mem: '.sprintf("%.4f Kb", ($totals['mem']+$totals_configs['mem'])/1024).' Time: '.sprintf("%.4f", $totals['time']+$totals_configs['time']));
}
- }*/
+ }
$is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == 'yes';
$skip_reporting = $this->constOn('DBG_SKIP_REPORTING') || $this->constOn('DBG_ZEND_PRESENT');
Index: branches/RC/core/kernel/nparser/nparser.php
===================================================================
diff -u -r10494 -r10580
--- branches/RC/core/kernel/nparser/nparser.php (.../nparser.php) (revision 10494)
+++ branches/RC/core/kernel/nparser/nparser.php (.../nparser.php) (revision 10580)
@@ -27,6 +27,30 @@
{
$data = file_get_contents($pre_parsed['tname']);
+ $this->CompileRaw($data, $pre_parsed['tname']);
+
+ // saving compiled version
+ $compiled = fopen($pre_parsed['fname'], 'w');
+ if (!fwrite($compiled, $this->Buffers[0])) {
+ trigger_error('Saving compiled template failed', E_USER_ERROR);
+ }
+ fclose($compiled);
+ return true;
+ }
+
+ function Parse($raw_template, $name=null)
+ {
+ $this->CompileRaw($raw_template, $name);
+ ob_start();
+ $_parser =& $this;
+ eval('?'.'>'.$this->Buffers[0]);
+ $output = ob_get_contents();
+ ob_end_clean();
+ return $output;
+ }
+
+ function CompileRaw($data, $t_name)
+ {
$code = "extract (\$_parser->Params);\n";
$this->Buffers[0] = ''."php $code ?>\n";
@@ -41,7 +65,7 @@
'tag' => $tag_data[3][0],
'closing' => $tag_data[4][0],
'line' => substr_count(substr($data, 0, $tag_data[2][1]), "\n")+1,
- 'file' => $pre_parsed['tname'],
+ 'file' => $t_name,
);
// the idea is to count number of comment openings and closings before current tag
@@ -74,14 +98,7 @@
// appending text data after last tag (after its closing pos),
// if no tag was found at all ($tag_data is not set) - append the whole $data
$this->Buffers[$this->Level] .= isset($tag_data) ? substr($data, $tag_data[4][1]+strlen($tag_data[4][0])) : $data;
-
- // saving compiled version
- $compiled = fopen($pre_parsed['fname'], 'w');
- if (!fwrite($compiled, $this->Buffers[0])) {
- trigger_error('Saving compiled template failed', E_USER_ERROR);
- }
- fclose($compiled);
- return true;
+ $this->Buffers[$this->Level] = preg_replace('//s', '', $this->Buffers[$this->Level]); // remove hidden comments IB#23065
}
function SplitParamsStr($params_str)
@@ -242,12 +259,16 @@
ob_start();
$_parser =& $this;
if ($pre_parsed['mode'] == 'file') {
+ if (false && $result = $this->Application->getCache('nparser', $pre_parsed['fname'])) {
+ return $result;
+ }
include($pre_parsed['fname']);
}
else {
eval('?'.'>'.$pre_parsed['content']);
}
$output = ob_get_contents();
+ // $this->Application->setCache('nparser', $pre_parsed['fname'], $output);
ob_end_clean();
return $output;
Index: branches/RC/core/kernel/session/session.php
===================================================================
diff -u -r10458 -r10580
--- branches/RC/core/kernel/session/session.php (.../session.php) (revision 10458)
+++ branches/RC/core/kernel/session/session.php (.../session.php) (revision 10580)
@@ -459,6 +459,7 @@
$this->Data = new Params();
$tmp_sid = $this->GetPassedSIDValue();
+// if (!$tmp_sid) return;
$check = $this->Check();
if( !(defined('IS_INSTALL') && IS_INSTALL) )
Index: branches/RC/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -r10459 -r10580
--- branches/RC/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 10459)
+++ branches/RC/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 10580)
@@ -49,6 +49,9 @@
'UseOutputCompression',
'OutputCompressionLevel',
'KeepSessionOnBrowserClose',
+ 'Config_Server_Time',
+ 'Config_Site_Time',
+ 'UseChangeLog',
);
foreach ($config_vars as $var) {
@@ -76,17 +79,25 @@
);
$conn =& $this->Application->GetADODBConnection();
- $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("configs_parsed", '.$conn->qstr(serialize($cache)).', '.adodb_mktime().')');
- $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.adodb_mktime().')');
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->set('master:configs_parsed', serialize($cache));
+ $this->Application->Memcached->set('master:config_files', serialize($this->configFiles));
+ }
+ else {
+ $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("configs_parsed", '.$conn->qstr(serialize($cache)).', '.adodb_mktime().')');
+ $conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.adodb_mktime().')');
+ }
unset($this->configFiles);
}
function RestoreParsedData()
{
$conn =& $this->Application->GetADODBConnection();
- $data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "configs_parsed"');
- if ($data && $data['Cached'] > 0 ) {
- $cache = unserialize($data['Data']);
+ if (!isset($this->Application->Memcached) || !($data = $this->Application->Memcached->get('master:configs_parsed'))) {
+ $data = $conn->GetOne('SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "configs_parsed"');
+ }
+ if ($data) {
+ $cache = unserialize($data);
$this->Application->Factory->Files = $cache['Factory.Files'];
$this->Application->Factory->realClasses = $cache['Factory.realClasses'];
$this->Application->Factory->Dependencies = $cache['Factory.Dependencies'];
@@ -121,9 +132,15 @@
{
$conn =& $this->Application->GetADODBConnection();
$conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "configs_parsed"');
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->delete('master:configs_parsed');
+ }
if ($include_sections) {
$conn->Query('DELETE FROM '.TABLE_PREFIX.'Cache WHERE VarName = "sections_parsed"');
+ if (isset($this->Application->Memcached)) {
+ $this->Application->Memcached->delete('master:sections_parsed');
+ }
}
}
@@ -179,11 +196,12 @@
$this->Application->refreshModuleInfo();
$conn =& $this->Application->GetADODBConnection();
- $data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"');
+ if (!isset($this->Application->Memcached) || !($data = $this->Application->Memcached->get('master:config_files'))) {
+ $data = $conn->GetOne('SELECT Data FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"');
+ }
if ($cache && $data) {
- $this->configFiles = unserialize($data['Data']);
+ $this->configFiles = unserialize($data);
shuffle($this->configFiles);
- $files_cached = $data['Cached'];
}
else {
$this->findConfigFiles($folderPath); // search from base directory
Index: branches/RC/core/kernel/utility/cache.php
===================================================================
diff -u -r10566 -r10580
--- branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 10566)
+++ branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 10580)
@@ -44,7 +44,7 @@
*/
function setCache($cache_name, $key, $value, $expires = 3600)
{
- $this->_storage->set($cache_name, $key, $value, $expires);
+ return $this->_storage->set($cache_name, $key, $value, $expires);
}
/**
@@ -188,7 +188,7 @@
*/
function set($cache_name, $key, $value, $expires)
{
- $this->_handler->set($cache_name . '-' . $key, $value, false, $expires); // false could be MEMCACHE_COMPRESSED to compress values in memory
+ return $this->_handler->set($cache_name . '-' . $key, $value, false, $expires); // false could be MEMCACHE_COMPRESSED to compress values in memory
}
/**
Index: branches/RC/core/kernel/application.php
===================================================================
diff -u -r10516 -r10580
--- branches/RC/core/kernel/application.php (.../application.php) (revision 10516)
+++ branches/RC/core/kernel/application.php (.../application.php) (revision 10580)
@@ -176,6 +176,13 @@
* @var unknown_type
*/
var $CurrentNTag = null;
+
+ /**
+ * Memcache object pointer
+ *
+ * @var Memcache
+ */
+ var $Memcached = null;
/**
* Returns kApplication instance anywhere in the script.
@@ -211,7 +218,21 @@
}
return $instance;
}
+
+ function InitMemcached()
+ {
+ $memcached_servers = 'localhost:11211'; // $this->Application->ConfigValue('MemcachedServers');
+ if ($memcached_servers && class_exists('Memcache')) {
+ $this->Memcached = new Memcache();
+ $servers = explode(';', $memcached_servers);
+ foreach ($servers as $server) {
+ list ($server, $port) = strpos($server, ':') !== false ? explode(':', $server, 2) : Array ($server, 11211);
+ $this->Memcached->addServer($server, $port);
+ }
+ }
+ }
+
/**
* Initializes the Application
*
@@ -224,7 +245,9 @@
function Init()
{
if($this->InitDone) return false;
-
+
+// $this->InitMemcached();
+
if (!constOn('SKIP_OUT_COMPRESSION')) {
ob_start(); // collect any output from method (other then tags) into buffer
}
@@ -253,26 +276,55 @@
$this->RegisterDefaultBuildEvents();
$this->SetDefaultConstants();
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Before UnitConfigReader');
+ }
+
$this->UnitConfigReader =& $this->recallObject('kUnitConfigReader');
$this->UnitConfigReader->scanModules(MODULES_PATH);
$this->registerModuleConstants();
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('After UnitConfigReader');
+ }
+
$rewrite_on = $this->ConfigValue('UseModRewrite');
// admin=1 - when front is browsed using admin session
$admin_on = getArrayValue($_REQUEST, 'admin') || $this->IsAdmin();
define('MOD_REWRITE', $rewrite_on && !$admin_on ? 1 : 0);
$this->HttpQuery =& $this->recallObject('HTTPQuery');
+
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Processed HTTPQuery initial');
+ }
+
$this->Session =& $this->recallObject('Session');
+
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Processed Session');
+ }
$this->HttpQuery->AfterInit();
+
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Processed HTTPQuery AfterInit');
+ }
$this->LoadCache();
$this->InitConfig();
$this->Phrases->Init('phrases');
+
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Loaded cache and phrases');
+ }
$this->UnitConfigReader->AfterConfigRead();
+
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
+ $this->Debugger->appendTimestamp('Processed AfterConfigRead');
+ }
/*// Module items are recalled during url parsing & PhrasesCache is needed already there,
@@ -302,7 +354,7 @@
$this->ValidateLogin();
- if($this->isDebugMode()) {
+ if( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->profileFinish('kernel4_startup');
}
@@ -421,10 +473,8 @@
$theme_id = $this->GetVar('m_theme');
if (!$theme_id) {
- $theme_id = $this->GetDefaultThemeId(1); //1 to force front-end mode!
- if (!$theme_id) {
- return false;
- }
+// $theme_id = $this->GetDefaultThemeId(1); //1 to force front-end mode!
+ $theme_id = 'default';
}
$this->SetVar('m_theme', $theme_id);
$this->SetVar('theme.current_id', $theme_id ); // KOSTJA: this is to fool theme' getPassedId
@@ -632,12 +682,12 @@
* @param int $key key name to add to cache
* @param mixed $value value of chached record
*/
- function setCache($cache_name, $key, $value)
+ function setCache($cache_name, $key, $value, $expiration=3600)
{
$cache =& $this->recallObject('Cache');
/* @var $cache kCache */
- $cache->setCache($cache_name, $key, $value);
+ return $cache->setCache($cache_name, $key, $value, $expiration);
}
/**