dr_lucas Posted June 24, 2010 Posted June 24, 2010 This article is copied from oscommercex.com because it does no longer exist and I didn’t want the information to get lost because of that. All credits go to the original author. The reason I post it here is to encourage discussion and improvement of this brilliant solution. As we know – store speed is one of the most important factors for a successful ecommerce store and if your store has many products on it and/or many contributions and queries it may get very slow and very cpu/ram hungry, in which case you will probably need to move your site to a more expensive hosting . This is a software solution which can dramatically reduce those hardware upgrade costs and generally speed us the store even if it’s just a vanilla installation or a heavily modified one. All text below is (almost) completely untouched. Please do contribute to this discussion, especially in regards to using memcached for caching the MySQL queries, which are usually the major bottleneck: At this topic we will talk about how you can speed up your osCommerce store with existing solutions and you will learn a new upcoming caching system which was developing by osCommercex. You will read: What is memcached? How memcached osCommerce works? Existing osCommerce Performans Module. Existing osCommerce Addons. What is memcached? Nowadays we are working on a new caching system for osCommerce. We named this module memcached osCommerce. Main problem about an e-commerce store is speed. One of my customer has a big book store. And he want to use good resolution images with over 2000 products. At this point I search some caching system. Then I realize a caching system that’s name is memcached. memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of web servers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss. First of all you need to install memcached to your server. To learn memcached you can visit: Memcached Documentation (Google Code Pages) Memcached Resources / Articles / Books http://download.tang...hed%20Study.pdf http://www.bytebot.n...-mysql-tutorial Memcached Functions for MySQL http://tangent.org/5...bmemcached.html Installing memcache on Windows for PHP Using Memcache with MySQL and PHP PHP memcahed Caching & Performance: Lessons from Facebook Using MySQL with memcached memcache.php stats like apc.php How memcached osCommerce works? After installing memcached you need to start it. Acording to your server operating system you can learn how you can start memcached server from documantations. For instance I am using Vista and I started it under services menu. Let’s look how we will store pages. Our osCommerce page is consisting 5 part. Header (header.php) Left column (column_left.php) Middle part of site Right column (column_right.php) Footer (footer.php) In order to use memcache first of all we will start memcache server osCommerce and will use PHP ob_start function. Also you can check Caching PHP Pages with Output Buffering. Now I am testing memcached osCommerce, so I will give brief information how memcached osCommerce works. First we will build memcache connection. $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); After success connection, we will look memcache server for existing key which was prepared for our store. I used osc_key for collecting results. $get_result = $memcache->get('osc_key'); Now we will check if memcache has osc_key. $start_memcache =false; if(!$memcache->get('osc_key')){ // if memcache has not osc_key, define start_memcache true. $osc_mem->author = "www.osCommercex.com"; $start_memcache = true; }else{ // if memcache has osc_key, get osc_key values to $osc_mem variable $osc_mem = $memcache->get('osc_key'); //echo "cache working: ".$osc_mem->author; //print_r($osCommerce_memcache); } We will put below code to application_top.php file. Find below line, define('PAGE_PARSE_START_TIME', microtime()); After this line add below code, $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Could not connect"); $get_result = $memcache->get('osc_key'); $start_memcache =false; if(!$memcache->get('osc_key')){ // if memcache has not osc_key, define start_memcache true. $osc_mem->author = "www.osCommercex.com"; $start_memcache = true; }else{// if memcache has osc_key, get osc_key values to $osc_mem variable $osc_mem = $memcache->get('osc_key'); //echo "cache working: ".$osc_mem->author; //print_r($osCommerce_memcache); } In application_top.php I am generating cached files name. For example, // we will decide the cached page name according to request $request_array = array_merge( $_GET, $_POST, $HTTP_GET_VARS ? $HTTP_GET_VARS : array( ), $HTTP_POST_VARS ? $HTTP_POST_VARS : array( ) ); print_r($request); echo $request['cPath']; $left_memcache_name = (isset($request_array['cPath'])?$request_array['cPath']:'').(isset($language)?$language:''); $bottom_memcache_name = (isset($language)?$language:''); //$cache_name_builder = (isset($request['cPath'])?$request['cPath']:'').(isset($request['products_id'])?$request['products_id']:'').(isset($language)?$language:''); $leftblokname = isset($left_memcache_name)?'leftblock'.$left_memcache_name:'leftblock'; $bottomname = isset($bottom_memcache_name)?'bottom'.$bottom_memcache_name:'bottom'; As you see we generate file names client requests and site languages. Therefore we can cache all possible pages. For instance I will cache column_leftp.php to memcached server. <?php /* $Id: column_left.php 1739 2007-12-20 00:52:16Z hpdl $ osCommerce, Open Source E-Commerce Solutions http://www.osCommerce .com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ if(empty($osc_mem->$leftblokname)){ $start_memcache = true; } // if start_memcache is false we will use cached files from memcached otherwise we will cache the file if(!$start_memcache){ echo "cache"; // for testing //if you decide to use gzip you can uncomment below line //echo gzuncompress($osc_mem->$leftblokname); echo $osc_mem->$leftblokname; }else{ ob_start(); if ((USE_CACHE == 'true') && empty($SID)) { echo tep_cache_categories_box(); } else { include(DIR_WS_BOXES . 'categories.php'); } if ((USE_CACHE == 'true') && empty($SID)) { echo tep_cache_manufacturers_box(); } else { include(DIR_WS_BOXES . 'manufacturers.php'); } require(DIR_WS_BOXES . 'whats_new.php'); require(DIR_WS_BOXES . 'search.php'); require(DIR_WS_BOXES . 'information.php'); //if you want you can gzip webpage you can use below line, wonderful! //$osc_mem->$leftblokname = gzcompress(ob_get_contents(),9); $osc_mem->$leftblokname = ob_get_contents(); ob_end_flush(); ob_end_clean(); } ?> As you see you can do same procedure for other part of site. And the last step you have to do is about application_bottom.php. Open application_bottom.php, And last ?> tag add below lines. if($start_memcache){ $memcache->set('osc_key', $osc_mem, false, 3600) or die ("Failed to save data at the server"); } Above codes we are caching osc_key with $osc_mem values for an hour. This is the main working procedure memcached osCommerce. There are some other way to use memcache, for instance you can cache sql queries. There is a function packet for MySQL for managing sql caching. You can get more information from Using MySQL with memcached. There are lots of ways to use memcached. The best part of memcached osCommerce, you can apply same way to your existing store no matter how modified it is. Did I help you? Click "Like" or "Thanks"! It's free of charge. :)My contributions:Total Configuration (newly updated 07/2018, for both osC 2.2 and 2.3.4.1 BS Frozen CE)User Tracking with Admin 1.0 (newly updated 07/2018)FedEx - Web Services v9, FAQ System , Who's Online Enhancement, Order Editor, MoneyBookers IPN, Ship in Cart (MS2), Admin Products Paging, Margin Report v1.00, 2Checkout INS / IPN (Instant Notification System) for MS2.2, Visitor Web Stats, Time Zone Offset - Adjust to match your location, Category Meta Tags
Guest Posted July 9, 2010 Posted July 9, 2010 Im interest to hear what sort of speed improvements people have noticed including category and product counts. Im at the point where I need to move to VPS and if Im going to pay for speed, Id like to squeeze all I can out of it.
Jan Zonjee Posted July 10, 2010 Posted July 10, 2010 Im interest to hear what sort of speed improvements people have noticed including category and product counts. A lot of people have achieved dramatic speed improvements just by analyzing first the amount of queries and time it takes for those queries and then changing things in their shop to tackle those particular issues. A good start would be to add KissER Error Handling & Debugging first and see what that shows you. If you use a PHP version lower than 5.2 I would suggest Output Queries Debug instead.
Guest Posted July 12, 2010 Posted July 12, 2010 I already have Output Queries Debug installed, though didnt realise FWR Media had released a new one till it was installed. I dont have any query issues I know of and speed is great, with none of the site being cache at all and 71 queries within 0.069secs and an initial page load of 2.5secs with Im pretty much being greedy wanting more than I have, but I am also planning for the future so I dont have to added something later and work out any kinks now.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.