This is my 2 modifications.
1. I modify Cache.php library for using Memcached server. Parameters for it in Config.php:
// CACHE
define('CACHE_DRIVER', 'memcached');
define('MEMCACHE_HOSTNAME', 'localhost');
define('MEMCACHE_PORT', '11211');
define('MEMCACHE_NAMESPACE', 'opencart_test');
If have not connection to memcached server, used standart file cache.
2. I create new DB module with cached SQL query. This may by good for hi loaded shops. It is can used over standart DB_DRIVER option:
define('DB_DRIVER', 'mysql_cached');
define('DB_CACHED_EXPIRE', 120);
For reset SQL cache, you can save in cache with key 'sql_globalresetcache' current time (time()).
1. I modify Cache.php library for using Memcached server. Parameters for it in Config.php:
// CACHE
define('CACHE_DRIVER', 'memcached');
define('MEMCACHE_HOSTNAME', 'localhost');
define('MEMCACHE_PORT', '11211');
define('MEMCACHE_NAMESPACE', 'opencart_test');
If have not connection to memcached server, used standart file cache.
2. I create new DB module with cached SQL query. This may by good for hi loaded shops. It is can used over standart DB_DRIVER option:
define('DB_DRIVER', 'mysql_cached');
define('DB_CACHED_EXPIRE', 120);
For reset SQL cache, you can save in cache with key 'sql_globalresetcache' current time (time()).
Attachments
Cache.php with memcached support & mysql_cached DB driver
I can't seem to find what should i modify, i did a compare to my file and yours and found tons of changes, tried to use your file and gave many errors.
can you give a step by step what to add/modify in my current opencart install?
OC 1.5.1.3
can you give a step by step what to add/modify in my current opencart install?
OC 1.5.1.3
For OC v1.5.2.1 release,
mysql_cached.php file would require the following changes:
for:
and all instances of:
replaced by:
- As an extra step for any OC version to increase cache security file algorithm -
Find:
add after:
Then, find:
add after:
Then, at the end of the file, find:
add after:
Then, find:
replace with:
mysql_cached.php file would require the following changes:
Code: Select all
private $connection;
Code: Select all
private $link;
Code: Select all
$this->connection
Code: Select all
$this->link
Find:
Code: Select all
private $cachedquery;
Code: Select all
private $request;
Code: Select all
$this->cache = new Cache(DB_CACHED_EXPIRE);
Code: Select all
$this->request = new Request();
Code: Select all
public function __destruct() {
mysql_close($this->connection);
}
Code: Select all
public function hashed_query($namespace = '') {
static $hashed_namespace = '';
$uid = uniqid(rand(), true);
$data = $namespace;
$data .= $this->request->server['REQUEST_TIME'];
$data .= (isset($this->request->server['HTTP_USER_AGENT'])) ? $this->request->server['HTTP_USER_AGENT'] : getenv('HTTP_USER_AGENT');
$data .= (isset($this->request->server['LOCAL_ADDR'])) ? $this->request->server['LOCAL_ADDR'] : getenv('LOCAL_ADDR');
$data .= $this->request->server['LOCAL_PORT'];
$data .= (isset($this->request->server['REMOTE_ADDR'])) ? $this->request->server['REMOTE_ADDR'] : getenv('REMOTE_ADDR');
$data .= (isset($this->request->server['REMOTE_PORT'])) ? $this->request->server['REMOTE_PORT'] : getenv('REMOTE_PORT');
if (extension_loaded('hash')) {
$hash = strtoupper(hash('ripemd128', $uid . $hashed_namespace . md5($data)));
} else {
$hash = strtoupper($uid . $hashed_namespace . md5($data));
}
$hashed_namespace = '{' .
substr($hash, 0, 8) .
'-' .
substr($hash, 8, 4) .
'-' .
substr($hash, 12, 4) .
'-' .
substr($hash, 16, 4) .
'-' .
substr($hash, 20, 12) .
'}';
return $hashed_namespace;
}
Code: Select all
$md5query = md5($sql);
Code: Select all
$md5query = $this->hashed_query($sql);
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
It shouldn't have any difference on that end.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
@straightlight
I got this error:
Line 134 content:
If i disable db driver options i get this
In my admin panel i got this error too:
session.php Line content:
cache.php Line content:
I got this error:
Code: Select all
Notice: Undefined index: LOCAL_PORT in /home/public_html/system/database/mysql_cached.php on line 134
Code: Select all
$data .= $this->request->server['LOCAL_PORT'];
In my admin panel i got this error too:
Code: Select all
Notice: Use of undefined constant CACHE_DRIVER - assumed 'CACHE_DRIVER' in /home/public_html/system/library/cache.php on line 10Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/public_html/admin/index.php:83) in /home/scctdsco/public_html/system/library/session.php on line 11
Code: Select all
session_start();
Code: Select all
if (CACHE_DRIVER == 'memcached')
1. Memcached
1. memcache is running over a socket (memcached -d -m 100 -s ~/var/memcached.sock)
2. replace the downloaded cache.php into this order /opencart/system/library (I took the file from here https://github.com/shaman/opencart-memcached)
3. configure my config. php with
socket works like this: http://www.php.net/manual/de/memcache.connect.php
When I'm clicking around the front the memory of the memcached process is going a bit up, but when I switch to the admin site I receive the following errror (notice) message:
Wonder now what that means?
2. mysql_cached
it seems that mysql_cached is working, only the memcached is responsible for those following error messages
I did the following
1. Downloaded the file mysql_cached.php (https://github.com/shaman/opencart-mysql-cache)
2. Moved to /opencart/system/database/mysql_cached.php
3. edit the config.php with
And receive now in the admin section the error:
Systeminformation
1. PHP:
2. MEMCACHE
- PHP Module (-m) is installed (memcache)
- memcached 1.4.4
- opencart latest version (v1.5.3.1 May 25, 2012), no additional plugins installed
bye
Marcel
1. memcache is running over a socket (memcached -d -m 100 -s ~/var/memcached.sock)
2. replace the downloaded cache.php into this order /opencart/system/library (I took the file from here https://github.com/shaman/opencart-memcached)
3. configure my config. php with
Code: Select all
// CACHE
define('CACHE_DRIVER', 'memcached');
define('MEMCACHE_HOSTNAME', 'unix:///home/lotek/var/memcached.sock');
define('MEMCACHE_PORT', '0');
define('MEMCACHE_NAMESPACE', 'opencart');
When I'm clicking around the front the memory of the memcached process is going a bit up, but when I switch to the admin site I receive the following errror (notice) message:
Code: Select all
Notice: Use of undefined constant CACHE_DRIVER - assumed 'CACHE_DRIVER' in /home/lotek/webapps/opencart/system/library/cache.php on line 31Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/lotek/webapps/opencart/admin/index.php:79) in /home/lotek/webapps/opencart/system/library/session.php on line 11
2. mysql_cached
it seems that mysql_cached is working, only the memcached is responsible for those following error messages
I did the following
1. Downloaded the file mysql_cached.php (https://github.com/shaman/opencart-mysql-cache)
2. Moved to /opencart/system/database/mysql_cached.php
3. edit the config.php with
Code: Select all
define('DB_DRIVER', 'mysql_cached');
define('DB_CACHED_EXPIRE', 120);
Code: Select all
Notice: Use of undefined constant CACHE_DRIVER - assumed 'CACHE_DRIVER' in /home/lotek/webapps/opencart/system/library/cache.php on line 31Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/lotek/webapps/opencart/admin/index.php:79) in /home/lotek/webapps/opencart/system/library/session.php on line 11Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/lotek/webapps/opencart/admin/index.php:79) in /home/lotek/webapps/opencart/system/library/session.php on line 11Warning: Cannot modify header information - headers already sent by (output started at /home/lotek/webapps/opencart/admin/index.php:79) in /home/lotek/webapps/opencart/system/engine/controller.php on line 28Warning: Cannot modify header information - headers already sent by (output started at /home/lotek/webapps/opencart/admin/index.php:79) in /home/lotek/webapps/opencart/system/engine/controller.php on line 29
1. PHP:
Code: Select all
PHP 5.2.17 (cli) (built: Jan 17 2012 13:19:44)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
with the ionCube PHP Loader v4.0.10, Copyright (c) 2002-2011, by ionCube Ltd., and
with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies
- PHP Module (-m) is installed (memcache)
- memcached 1.4.4
- opencart latest version (v1.5.3.1 May 25, 2012), no additional plugins installed
bye
Marcel
You should put following code in /admin/config.php either.
// CACHE
define('CACHE_DRIVER', 'memcached');
define('MEMCACHE_HOSTNAME', 'unix:///home/lotek/var/memcached.sock');
define('MEMCACHE_PORT', '0');
define('MEMCACHE_NAMESPACE', 'opencart');
// CACHE
define('CACHE_DRIVER', 'memcached');
define('MEMCACHE_HOSTNAME', 'unix:///home/lotek/var/memcached.sock');
define('MEMCACHE_PORT', '0');
define('MEMCACHE_NAMESPACE', 'opencart');
Found out this mod pretty much halves the processing time for requests, or in other terms, makes the site twice as fast.
Straightlight, I just tested this modification with the changes you recommended and I am also receiving the error mentioned above (Undefined index: LOCAL_PORT in /home/*/public_html/*/system/database/mysql_cached.php on line 129).
If I revert back to the original mysql_cached.php file supplied in the first post, the error disappears. Unfortunately this is beyond my scope of understanding. Would you be able to advise why the changes you posted are necessary and also if this would vary for OpenCart v1.5.5.1?
If I revert back to the original mysql_cached.php file supplied in the first post, the error disappears. Unfortunately this is beyond my scope of understanding. Would you be able to advise why the changes you posted are necessary and also if this would vary for OpenCart v1.5.5.1?
Who is online
Users browsing this forum: No registered users and 130 guests