I recently added a few products to my Zen Cart installation that have lots of attributes. Previously, I had not noticed any performance issues with the cart, but now I am intensely aware of it.
I own my own server: a brand new dual core, dual CPU Xeon w/ 3 GB RAM, and I know that the load average is typically 0. Performance should not be an issue.
Nonetheless, my attribute-laden products take between 50 and 60 seconds to show up. I have tuned the server to the best of my ability, and turned on DB caching.
Since 60 seconds is simply not acceptable, I have implemented a workaround using PEAR cache_lite. It was surprisingly easy to implement.
Note that this solution may not work for you, depending on how "dynamic" your site is.
First I installed PEAR cache_lite. I have root access, so this was easy. I think pear libraries can be included without root access, but I'm not an expert on that.
then I opened up catalog/includes/templates/<my_template>/common/tpl_main_page.phpCode:#> pear install cache_lite
and found the lines:
I have a heavily customized installation, but it should be around line 120 or so.Code:<?php /** * prepares and displays center column * */ require($body_code); ?>
I changed this area of the file to look like this:
I know, not pretty, but it works.Code:<?php require_once('Cache/Lite/Output.php'); $options = array( 'cacheDir' => '/tmp/', 'lifeTime' => (60*60*24) ); $cache = new Cache_Lite_Output($options); if (isset($_GET['products_id'])) { if (!($cache->start($_SERVER['REQUEST_URI']))) { ?> <?php /** * prepares and displays center column * */ require($body_code); ?> <?php $cache->end(); } } else { /** * prepares and displays center column * */ require($body_code); } ?>
What this does is create a 24 hour cache for all pages where product_id is set. These are the product_info pages, i.e., the pages that display all the attributes.
I then set up a cron job to clear and regenerate the cache in the middle of the night.
The cron is not explicitly necessary, as the cache will automatically expire in 24 hours, but I never want a user to be faced with the 60 second delay as the page rebuilds. If you don't have access to cron, you may want to set your cache to never expire, and manage the cache manually.
clearcache.php
Code:html> <body> <?php require_once 'Cache/Lite.php'; $options = array('cacheDir' => '/tmp/'); $cache = new Cache_Lite($options); $cache->clean(); ?> Cache Cleaned. </body> </html>
cron jobs:
This will clear the cache at 3:40 AM, then spider the site at 3:41 to cause the cache to be rebuilt.Code:40 3 * * * wget -o /dev/null -O - http://www.mydomain.com/admin/clearcache.php >/dev/null 2>&1 41 3 * * * wget -r -nd --delete-after http://www.mydomain.com >/dev/null 2>&1
results:
My pages that took 50-60 seconds to display now come up in 0.175 seconds. 9718 DB queries, down to 65.
Before:
After:Code:Parse Time: 53 - Number of Queries: 9718 - Query Time: 3
Quite an improvement!Code:Parse Time: 0.175 - Number of Queries: 65 - Query Time: 0.01790659312439
Again, this solution appears to work for me (so far). You may get different mileage depending on your store set up.
Zen developers, feel free to throw stones at me if I'm way off base.
My Installation:
Server OS: Linux 2.6.9 (Fedora Core 5)
Database: MySQL 4.1.20
PHP Version: 5.1.6 (Zend: 2.1.0)
HTTP Server: Apache/2.2.2 (Fedora)
Zen Cart 1.3.0.2 (yes, I'm behind...)
Database Patch Level: 1.3.0.2






Bookmarks