This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

dsf

  • *****
  • 261 posts
Memcache(d) Questions and Issues
« on: December 08, 2022, 09:14:21 AM »
Hi,

Just got memcache(d) support in my Cpanel and i tried to enable it for Osclass 8, and failed.

I would like to ask first if memcache should be used or memcached? What is supported in Osclass?

Also trying both, i failed with an error:

[08-Dec-2022 00:01:58 America/Los_Angeles] PHP Notice:  MemcachePool::get(): Server /home/memcached.sock (tcp 0, udp 0) failed with: Connection failed: Failed to parse address "/home/memcached.sock" (0) in /home/public_html/oc-includes/osclass/core/caches/Object_Cache_memcache.php on line 143

I asked my hosting and got this reply:

Quote
Unfortunately that means you'll need to reach out to the plugin developer to ask them how to use a socket instead of a port.

I was also told to use "memcached" and not "memcache".

Thanks
« Last Edit: December 08, 2022, 09:17:01 AM by dsf »

*

MB Themes

Re: Memcache(d) Questions and Issues
« Reply #1 on: December 08, 2022, 08:40:29 PM »
Only one is supported, check config.php for details (do not remember which one)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #2 on: December 08, 2022, 08:55:22 PM »
I wrote that none of them is working and also i provided the error and the reply from my hoster.

Osclass uses some other way (tcp ports) and unix sockets are needed (as it works with Wordpress plugins and memcache).

And it is not currently supported from what i understand.

What shall i do?

Thanks


*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #3 on: December 08, 2022, 10:00:32 PM »
I see in DefinitionCache.php:


/**
 * Abstract class representing Definition cache managers that implements
 * useful common methods and is a factory.
 * @todo Create a separate maintenance file advanced users can use to
 *       cache their custom HTMLDefinition, which can be loaded
 *       via a configuration directive
 * @todo Implement memcached
 */

Apparently memcached is not implemented but @todo. never did ....

Any plans?

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #4 on: December 08, 2022, 10:42:34 PM »
I have found some old forum posts from a developer from some other site and the information is very usefull:

Quote
Osclass cache function file is based for Memcached extension.

Their are two thing in MemcacheD first is a daemon which you can install via yum or apt in your server, second Memcached/Memcahe are two extention for php to communicate with Memcached daemon.

Inner osclass MemcacheD class are for Memcached php extension.


Marked as best answer by frosticek on December 09, 2022, 04:59:07 PM
*

Wiz

  • ****
  • 138 posts
Re: Memcache(d) Questions and Issues
« Reply #5 on: December 09, 2022, 12:55:21 AM »
That's an easy one dsf ... They're basically telling you they don't support tcp memcache(d) and you'll have to instead use unix/socket ... so find out the unix socket path from them or by loading a php info page and paste as follows in config.php

Code: [Select]
$_cache_config[] = array('default_host' => 'unix:///path/to/memcache.socket', 'default_port' => 0, 'default_weight' => 1);
OR

Code: [Select]
$_cache_config[] = array('default_host' => 'unix:///path/to/memcache.socket:0', 'default_port' => '', 'default_weight' => 1);
Forgot to add: Memcache and memcached are interchangeable from a config and caching point of view ... it's just 1 is ancient yet still updated and the other one is more recent and actively updated.
« Last Edit: December 09, 2022, 08:44:18 PM by Wiz »

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #6 on: December 10, 2022, 11:30:26 AM »
Thank you Wiz, i will try that and update here the results and my findings, so more people will benefit it the future.

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #7 on: December 10, 2022, 12:49:16 PM »
It seems that Osclass doesn't support MemcacheD at all. Maybe Osclass can't use the unix sockets? I don't know.

With some help from our hosting company, we were not able to make this work with MemcacheD. Osclass reports extension not loaded.

Since Memcache is NOT supported in our setup, we were not able to test Memcache.

After our failure with Osclass, i tested MemcacheD with a Wordpress site hosted in the same plan. And worked easy and well.


here is the error:

 The Memcached Extension must be loaded to use Memcached Cache.
 Cache memcache NOT SUPPORTED - loaded Object_Cache_default cache


« Last Edit: December 10, 2022, 12:57:58 PM by dsf »

*

Wiz

  • ****
  • 138 posts
Re: Memcache(d) Questions and Issues
« Reply #8 on: December 11, 2022, 02:18:22 AM »
If you open the Object_Cache_memcache.php file in oc-includes/osclass/core/caches, you'll see from the code references to memcached ... the not supported message you're seeing is because of:

Code: [Select]
  public static function is_supported() {
  if ( !class_exists('Memcache') ) {
    error_log('The Memcached Extension must be loaded to use Memcached Cache.');
    return false;
  }
    return true;
  }

Change to

 
Code: [Select]
public static function is_supported() {
  if ( !class_exists('Memcached') ) {
    error_log('The Memcached Extension must be loaded to use Memcached Cache.');
    return false;
  }
    return true;
  }


I believe the reason you're not able to connect is due to the absence of a tcp connection to the memcached instance provided by your hosting company and the object cache module memcache in Osclass is designed to connect via tcp. So, to support memcached, open the above file and replace

Code: [Select]
protected $_memcache_conf   = array(
  'default' => array(
    'default_host' => '127.0.0.1',
    'default_port' => 11211,
    'default_weight' => 1
  )
  );

with

Code: [Select]
protected $_memcache_conf   = array(
  'default' => array(
    'default_host' => 'unix:///path/to/your/memcached.sock:0'
  )
  );

and replace

Code: [Select]
public function __construct() {
    $this->multisite = false;
  //  if(SiteInfo::newInstance()->siteInfo!=array()) {
  //    $info   = SiteInfo::newInstance()->siteInfo;
  //    $site_id  = osc_sanitizeString($info);
  //    $this->multisite = true;
  //  }

    $site_id = '';
    $this->site_prefix =  $this->multisite ? $site_id . ':' : '';
    $cache_server = array();
    global $_cache_config;
    if( !isset($_cache_config) && !is_array($_cache_config) ) {
      $_t['hostname'] = $this->_memcache_conf['default']['default_host'];
      $_t['port']   = $this->_memcache_conf['default']['default_port'];
      $_t['weight']   = $this->_memcache_conf['default']['default_weight'];
      $cache_server[] = $_t;
    } else {
      foreach($_cache_config as $_server) {
      $_array = array(
        'hostname' => $_server['default_host'],
        'port'   => $_server['default_port'],
        'weight'   => $_server['default_weight']
      );
      $cache_server[] = $_array;
      }
    }

    $this->_memcached = new Memcache();
    foreach($cache_server as $_config) {
      $this->_memcached->addServer($_config['hostname'], $_config['port'], $_config['weight']);
    }
  }

with

Code: [Select]
public function __construct() {
    $this->multisite = false;
  //  if(SiteInfo::newInstance()->siteInfo!=array()) {
  //    $info   = SiteInfo::newInstance()->siteInfo;
  //    $site_id  = osc_sanitizeString($info);
  //    $this->multisite = true;
  //  }

    $site_id = '';
    $this->site_prefix =  $this->multisite ? $site_id . ':' : '';
    $cache_server = array();
    global $_cache_config;
    if( !isset($_cache_config) && !is_array($_cache_config) ) {
      $_t['hostname'] = $this->_memcache_conf['default']['default_host'];
      $cache_server[] = $_t;
    } else {
      foreach($_cache_config as $_server) {
      $_array = array(
        'hostname' => $_server['default_host'],
      );
      $cache_server[] = $_array;
      }
    }

    $this->_memcached = new Memcached();
    foreach($cache_server as $_config) {
      $this->_memcached->addServer($_config['hostname']);
    }
  }
« Last Edit: December 11, 2022, 02:21:10 AM by Wiz »

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #9 on: December 12, 2022, 10:37:36 AM »
Wiz, dude much appreciated your help (working or not it doesnt' matter, help is help).

I will try all that and update here the next days.

Thanks again.

*

dsf

  • *****
  • 261 posts
Re: Memcache(d) Questions and Issues
« Reply #10 on: December 12, 2022, 12:02:24 PM »
Did all the changed and still get this error:


[12-Dec-2022 13:01:01 Europe/Athens] PHP Warning:  Memcached::addServer() expects at least 2 parameters, 1 given in /home/oc-includes/osclass/core/caches/Object_Cache_memcache.php on line 260


Line 260 is:


Code: [Select]
$this->_memcached->addServer($_config['hostname']);

*

Wiz

  • ****
  • 138 posts
Re: Memcache(d) Questions and Issues
« Reply #11 on: December 13, 2022, 04:31:28 AM »
No problem.

It's strange though that it's not working on your end - I have it working with both memcache and memcached running on unix socket in my dev environment ... triple check again, ie. sock permissions, sock path etc. and if it's still not working, try this -

1. Revert Object_Cache_memcache back to default file
2. Edit config.php with:

Code: [Select]
// MemCache caching option (database queries cache)
define('OSC_CACHE', 'memcached');
$_cache_config[] = array('default_host' => '/path/to/your/memcached.sock', 'default_port' => 0, 'default_weight' => 1);

3. Download the attached Object_Cache_memcached.php and place it in oc-includes/osclass/core/caches/ and test again... make sure file perms are 0644

4. If all fails, then it's your hosting provider.

See screenshots of working memcached on unix sock

Edit: missed something, edit line 195 in Object_Cache_memcached.php from:

Code: [Select]
return $this->_memcached->set( $key , $store_data , 0 , $expire );
to

Code: [Select]
return $this->_memcached->set( $key , $store_data, $expire );
« Last Edit: December 13, 2022, 04:48:27 AM by Wiz »

*

MB Themes

Re: Memcache(d) Questions and Issues
« Reply #12 on: December 13, 2022, 08:38:08 AM »
@Wiz
I am not sure guys, did not study that much, but would say that Osclass has only support for memcache and not memcached.
If you check last function:
Code: [Select]
  public function _get_cache() {
    return 'memcache';
  }

Word "memcached" might not be used appropriate in this class and could lead to confusion.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Wiz

  • ****
  • 138 posts
Re: Memcache(d) Questions and Issues
« Reply #13 on: December 13, 2022, 02:40:30 PM »
@MB

I really don't see anything wrong with extending osclass's caching capabilities as some of the current caching features / modules are very outdated especially since osclass's core has many code snippets copied over from wordpress.

Just helping here.

*

MB Themes

Re: Memcache(d) Questions and Issues
« Reply #14 on: December 13, 2022, 11:14:25 PM »
Maybe you can share your file Object_Cache_memcache.php file together with samole config enrry and can be added into next version  ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots