Search code examples
codeigniterwampmemcachedcodeigniter-2wampserver

codeigniter2 deploy on windows 10 with wamp server, memcached error fix


I am trying to run the old codigniter2 website on windows 10 with a wamp server.

But I get the following error:

A PHP Error was encountered
Severity: Error
Message: Call to a member function get() on null
Filename: C:/wamp64/www/website.test/system/libraries/Cache/drivers/Cache_memcached.php:52

full error img

What should I do?


Solution

  • I solved my problem:

    Step 1 (enable Memcache in WAMPserver):

    • download the Memcache package that compatible with your PHP version and Wamp version (32 or 64 bits). I download the Thread Safe one.
    • extract the downloaded package then copy the php_memcache.dll into your extensions folder of your PHP such as C:\wamp64\bin\php\php5.6.40\ext. The php5.6.40 is your PHP folder.
    • open the php.ini file and search for extension=php_bz2.dll which should be the first extension on the extensions list then copy extension=php_memcache.dll and paste at the end of the extensions list.
    • restart Wamp server
    • now you should see the Memcache loaded when you visit http://localhost

    If the steps above don’t work, you just open the error log file at the logs folder at the root directory and check the error there.

    Step 2 (Changes in /system/libraries/Cache/drivers/Cache_memcached.php):

    Using this github link, i made changes in Cache_memcached.php:

    Replace this:

    $this->_memcached = new Memcached();
    

    With this:

    if (class_exists('Memcached')) {
          $this->_memcached = new Memcached();
       }
       else if (class_exists('Memcache')) {
           $this->_memcached = new Memcache();
       }
       else {
              log_message('error', 'Failed to create object for Memcached Cache; extension not loaded?');
              return FALSE;        
       }
    

    And replace this:

    if ( ! extension_loaded('memcached'))
    

    With this:

    if ( ! extension_loaded('memcached') && ! extension_loaded('memcache'))
    

    Then delete (if exists):

    $this->_memcached->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
    $this->_memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
    

    And this (if exists):

    $this->_memcached->setOption(Memcached::OPT_PREFIX_KEY, $prefix);
    

    Step 3 (Refresh Database):

    • Delete and create new database
    • import data (if big data you can import it via wamp server mysql console "use dbname; source c:/wamp64/www/dataname.sql")
    • restart wamp server