Post by UncleAndy » Mon Mar 07, 2011 5:10 pm

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()).

Attachments

Cache.php with memcached support & mysql_cached DB driver


Newbie

Posts

Joined
Sun Mar 06, 2011 12:07 am

Post by anteater_sa » Thu Jul 28, 2011 6:27 pm

This is great, thanks!

Newbie

Posts

Joined
Mon Jul 18, 2011 7:19 pm

Post by danswano » Fri Mar 16, 2012 11:17 pm

How do i apply this to opencart 1.5.1.3?
I have memcache installed and running.

New member

Posts

Joined
Wed Mar 14, 2012 8:37 pm

Post by UncleAndy » Sat Mar 17, 2012 12:43 am

danswano wrote:How do i apply this to opencart 1.5.1.3?
I have memcache installed and running.
I think, you need manualy change cache module for memcached code.

Newbie

Posts

Joined
Sun Mar 06, 2011 12:07 am

Post by danswano » Mon Mar 19, 2012 1:11 am

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

New member

Posts

Joined
Wed Mar 14, 2012 8:37 pm

Post by Lancelot28 » Mon Mar 19, 2012 6:13 pm

ImageThis is great, thanks!

Newbie

Posts

Joined
Sat Mar 03, 2012 2:15 pm

Post by danswano » Mon Mar 19, 2012 9:06 pm

@Lancelot28
Did it work for you?

New member

Posts

Joined
Wed Mar 14, 2012 8:37 pm

Post by straightlight » Tue Mar 20, 2012 8:00 pm

For OC v1.5.2.1 release,

mysql_cached.php file would require the following changes:

Code: Select all

private $connection;
for:

Code: Select all

private $link;
and all instances of:

Code: Select all

$this->connection
replaced by:

Code: Select all

$this->link
- As an extra step for any OC version to increase cache security file algorithm -

Find:

Code: Select all

private $cachedquery;
add after:

Code: Select all

private $request;
Then, find:

Code: Select all

$this->cache = new Cache(DB_CACHED_EXPIRE);
add after:

Code: Select all

$this->request = new Request();
Then, at the end of the file, find:

Code: Select all

public function __destruct() {
		mysql_close($this->connection);
	}
add after:

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;
   }
Then, find:

Code: Select all

$md5query = md5($sql);
replace with:

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by danswano » Tue Mar 20, 2012 10:49 pm

@straightlight
Does this work on 1.5.1.3 too?

New member

Posts

Joined
Wed Mar 14, 2012 8:37 pm

Post by straightlight » Wed Mar 21, 2012 10:59 pm

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by danswano » Wed Mar 21, 2012 11:13 pm

@straightlight
I got this error:

Code: Select all

Notice: Undefined index: LOCAL_PORT in /home/public_html/system/database/mysql_cached.php on line 134
Line 134 content:

Code: Select all

          $data .= $this->request->server['LOCAL_PORT'];
If i disable db driver options i get this

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 
session.php Line content:

Code: Select all

			session_start();
cache.php Line content:

Code: Select all

  		if (CACHE_DRIVER == 'memcached')

New member

Posts

Joined
Wed Mar 14, 2012 8:37 pm

Post by DdTech » Wed Apr 18, 2012 4:16 am

Great Job.. Thanks You!!

Newbie

Posts

Joined
Tue Jan 10, 2012 10:55 am

Post by zch0071 » Wed May 16, 2012 2:26 pm

Thank you for your contribution!

New member

Posts

Joined
Sun Sep 20, 2009 12:10 am

Post by lotek » Thu Jun 21, 2012 6:05 pm

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

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');
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:

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
Wonder now what that means?

2. mysql_cached

:yahoo: 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);
And receive now in the admin section the error:

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
Systeminformation
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
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

Newbie

Posts

Joined
Fri Dec 17, 2010 5:48 am
Location - Switzerland

Post by Roman_SE » Mon Oct 22, 2012 11:58 pm

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');

Newbie

Posts

Joined
Mon Oct 22, 2012 11:56 pm

Post by realisaatio » Sun Feb 17, 2013 1:51 am

Found out this mod pretty much halves the processing time for requests, or in other terms, makes the site twice as fast.

Newbie

Posts

Joined
Fri Feb 15, 2013 7:08 pm

Post by Homayoun » Mon Mar 11, 2013 1:42 am

Hello all,

Any guidance on how to use this on OC 1.5.5.1? Memcache is already on my server. Any tips or help will be appreciated.

Newbie

Posts

Joined
Tue Jan 22, 2013 2:57 pm

Post by deltaguns » Wed May 22, 2013 6:39 pm

I would also like an update for 1.5.5.1

New member

Posts

Joined
Wed Apr 24, 2013 7:03 pm

Post by UncleAndy » Wed May 22, 2013 6:45 pm

As I undested (watch some time ago) in version 1.5.* not changed drivers for DB. Then, you can use it in that version.

Newbie

Posts

Joined
Sun Mar 06, 2011 12:07 am

Post by storm-cloud » Mon Apr 07, 2014 7:11 am

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?

Active Member

Posts

Joined
Wed Feb 22, 2012 8:07 am
Who is online

Users browsing this forum: No registered users and 130 guests