0

Error from /var/log/system.log when memcached is enabled in local.xml:

2016-03-06T00:37:16+00:00 ERR (3): Warning: Division by zero in /public_html/demo/lib/Zend/Cache/Backend/Libmemcached.php on line 395

Site is on shared hosting with cloudlinux. Memcached part from local.xml looks like this:

<cache>
    <backend>memcached</backend>
    <slow_backend>database</slow_backend>
    <slow_backend_store_data>0</slow_backend_store_data>
    <auto_refresh_fast_cache>0</auto_refresh_fast_cache>
      <memcached>
        <servers>
            <server>
                <host><![CDATA[127.0.0.1]]></host>
                <port><![CDATA[11211]]></port>
                <persistent><![CDATA[1]]></persistent>
            </server>
        </servers>
        <compression><![CDATA[0]]></compression>
        <cache_dir><![CDATA[]]></cache_dir>
        <hashed_directory_level><![CDATA[]]></hashed_directory_level>
        <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
        <file_name_prefix><![CDATA[]]></file_name_prefix>
    </memcached>
</cache>

Any ideas, how to fix this? Do I need any fix in local.xml in order to avoid this error? I was checking CPU usage in cpanel and it's almost 88/100 all the time, if I disable memcached from local.xml, CPU usage drops to normal 22/100.

if ($memSize === null || $memUsed === null) {
    $mem = $this->_memcache->getstats();
    if (isset($mem['limit_maxbytes']) && $mem['limit_maxbytes'] > 0) {
        return ((int) (100 * ($mem['bytes'] / $mem['limit_maxbytes'])));
    } else {
        return 100;
    }

Line 395 is: } else {

  • If I recall this is a common issue due to newer version of php throwing notices while older php versions did not. Upgrading Magento to the latest may resolve the issue or digging inside the file you mentioned and adding zero checks – Vladimir Ramik Mar 06 '16 at 04:15
  • I use magento 1.7.0.2 on PHP 5.5. Since I use a lot od customizations, I don't really want to upgrade Magento yet. This is the part of php that's causing problem: if ($memSize === null || $memUsed === null) { $mem = $this->_memcache->getstats(); if (isset($mem['limit_maxbytes']) && $mem['limit_maxbytes'] > 0) { return ((int) (100 * ($mem['bytes'] / $mem['limit_maxbytes']))); } else { return 100; } No idea how to zero check this? – Samo Čretnik Mar 06 '16 at 21:18
  • Can you post the code formatted please into an edit of your question? The issue is during division - likely this part: ((int) (100 * ($mem['bytes'] / $mem['limit_maxbytes']))); – Vladimir Ramik Mar 06 '16 at 21:34

1 Answers1

0

Lowering the error reporting level by adding/modifying the following function call in index.php should suppress the warning message, but of course at some point of time you may want it to be turned back on and this annoying problem will come back...

error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING);

Hope this is helpful.