Osclass Support Forums

General osclass questions => General discussion => Topic started by: dsf on December 08, 2022, 09:14:21 AM

Title: Memcache(d) Questions and Issues
Post by: dsf 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
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 08, 2022, 08:40:29 PM
Only one is supported, check config.php for details (do not remember which one)
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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

Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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?
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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.

Title: Re: Memcache(d) Questions and Issues
Post by: Wiz 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.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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


Title: Re: Memcache(d) Questions and Issues
Post by: Wiz 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']);
    }
  }
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf 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']);
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz 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 );
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes 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.
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz 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.
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes 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  ;)
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 14, 2022, 09:35:29 AM
Maybe you can share your file Object_Cache_memcache.php file together with samole config enrry and can be added into next version  ;)

I already did, as a zip file, in my previous post   8)

I'll start another thread and include both versions of the updated classes.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on December 14, 2022, 03:45:21 PM
Wiz,

That latest fix (line 195) does the job.

I see no errors and also i see "Cache: Enabled (memcached)".

Thank you so much. I will test further in the staging site ....

Do you know if multiple Osclass sites hosted in the same plan (hosting space) can use that?
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on December 14, 2022, 04:11:15 PM
Wiz and MB Themes:

I asked the hosting support if multiple Osclass can use that (same plan). And here is their reply:

Quote
It would take some investigation and tweaking by your webmaster. Each instance/site will also need a separate key so the caching does not conflict.

So i guess something more is needed. Something like this, i see in other scripts using memecached:

Quote
supplementary_cache_options➡prefix:

The value specified here will be prepended to all cache entry keys. Default = "prefixsomething_". When multiple installations exist at the same server, this can be useful for keeping their caches separate from each other.

Still, i'm not a developer. You should know all about this and test further.
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 14, 2022, 10:12:12 PM
Wiz and MB Themes:

I asked the hosting support if multiple Osclass can use that (same plan). And here is their reply:

Quote
It would take some investigation and tweaking by your webmaster. Each instance/site will also need a separate key so the caching does not conflict.

So i guess something more is needed. Something like this, i see in other scripts using memecached:

Quote
supplementary_cache_options➡prefix:

The value specified here will be prepended to all cache entry keys. Default = "prefixsomething_". When multiple installations exist at the same server, this can be useful for keeping their caches separate from each other.

Still, i'm not a developer. You should know all about this and test further.

Not possible with memcache and memcached as they don't support partitioning / multiple namespaces so only solution is to run multiple instances of either ... for multiple sites on single caching instance, you'll need redis or similar caching stores
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on December 14, 2022, 10:28:15 PM
Wiz,

Correct, that memcache does not support partitioning. However you can do it in the site. What you would do is prefix any entry added with a unique prefix to each site.

memchached provides guidance on this: https://github.com/memcached/memcached/wiki/ProgrammingTricks

As i posted above. A prefix .....
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 15, 2022, 07:40:43 AM
Wiz,

Correct, that memcache does not support partitioning. However you can do it in the site. What you would do is prefix any entry added with a unique prefix to each site.

memchached provides guidance on this: https://github.com/memcached/memcached/wiki/ProgrammingTricks

As i posted above. A prefix .....

Possible, yes, but not so easy as that requires modifying multiple core files. Better hire a developer if you really needed the added functionality or simply find a hosting company that offers multiple memcached instances  or root access.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on December 16, 2022, 12:16:35 AM
Wiz,

Do you know if memcached works with Osclass multisite installation?

Thanks
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 17, 2022, 04:56:48 AM
I don't think multisite is working properly in osclass
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 17, 2022, 07:44:04 AM
I think cache entries keys will get subdomain in it, so it should be ok.
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 17, 2022, 09:27:17 AM
I think cache entries keys will get subdomain in it, so it should be ok.

Yes, for sub-domains it works and I can confirm this but he was asking about multisite .. sub-domain != multisite and multisite functionality is currently non-functional in osclass
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 17, 2022, 11:22:47 AM
Well it's quite confusing some times, but basically osclass has:
- multisite
- subdomain split installation (by user, category, country, region or city).

For multisite, it is possible to define also other sites related to this installation and we've been restoring one table that was missing for this in 8.0.3
Code: [Select]
CREATE TABLE %st_site (
      s_site VARCHAR(255) NOT NULL,
      s_site_mapping VARCHAR(255) NULL,
      fk_i_user_id INT(10) UNSIGNED NULL,
      s_db_name VARCHAR(64) NULL,
      s_db_host VARCHAR(255) NULL,
      s_db_user VARCHAR(64) NULL,
      s_db_password VARCHAR(255) NULL,
      s_upload_path VARCHAR(255) NULL,
      dt_date DATETIME NULL,

      PRIMARY KEY (s_site)
    ) ENGINE=InnoDB DEFAULT CHARACTER SET 'UTF8' COLLATE 'UTF8_GENERAL_CI';

Honestly I was never testing this, but it sounds like it could be great feature ;)


I am also not sure if it is expected that this table will be on DB_TABLE_PREFIX or is above that.
Only info I found:
Your config.php file the database configuration where the configuration for the Osclass sites are saved.
- It matches the url is trying to load with one of the ones that are in the database
- The rest of it woks as a standalone Osclass. It doesn't have a super admin to control all the Osclass yet.
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 17, 2022, 10:39:41 PM
I've been checking that multisite feature bit more.
It looks when you want to run multiple sites, but using just one database, there come multisite.
You define site in t_site table with relevant database details and mapping.
But, its not superclear to me why not just to update config.php.... probably would need testing.

What mske sense to me and what seems to be standard for multisite is prestashop model, that allows you to manage multiple osclass installations from one backoffice.

Question is, how many people runs mire than 2-3 osclass siyes and would actually benefit out of such feature.
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 18, 2022, 03:41:00 AM
Question is, how many people runs mire than 2-3 osclass siyes and would actually benefit out of such feature.

Not many and probably those needing to add and manage expanded and full-featured verticals such as Jobs, Vehicles or Properties etc. to their general classifieds platform and sharing users and ancillary services across such verticals.

I actually reached out to you some time back to try to get multisite working and had created the missing table but never managed to get it working properly as the platform was always erroring out with a 50x error as soon as the "multisite" config option was enabled in config.php
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 18, 2022, 12:55:49 PM
Right, as it use metadata DB that is not used by anything else..besides that I reviewed source code and only found that this table allows to use different DB than one in config.php.
Basically looks like solution to use 1 DB for multiple sites and have correct links etc.

I've been testing and it seems that metadata conne tion might not work properly as it was reporting that connection is already closed.

Besides same DB, files on hosting must be identical and not sure what was expectation when you create listing on site A, how it will look like on site B, as this site does not have related assets like images.

I think, based on github comments, it should be working somewhere between 3.0 and 3.3, could make sense to test these with some old Php & db versions if it really worked and how...

Right now it seems to be it would make sense to remove this from core, focus more on subdomain based setup & functionality (numerous updates in 8.0.3) and consider this feature in future but in way of connecting backoffice of osclass installations.
Title: Re: Memcache(d) Questions and Issues
Post by: Wiz on December 18, 2022, 08:05:03 PM
Right now it seems to be it would make sense to remove this from core, focus more on subdomain based setup & functionality (numerous updates in 8.0.3) and consider this feature in future but in way of connecting backoffice of osclass installations.

Couldn't agree more especially with having sub-domain specific listings posted under their respective sub-domains ie. listing posted with region or city A selected should show under country and/or region/city A but not under region/city B which is currently the case. Same goes for search, searching under region / city A sub-domain should only yield region / city A results.

Cheers
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on December 18, 2022, 09:55:14 PM
@Wiz
well we should probably add these filters automatically into models.
currently it works well just for latest listings.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 17, 2023, 05:34:38 PM
Guys hi,

Any plans to also include Redis object caching ?


Thanks
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 17, 2023, 05:58:07 PM
It does not look to be complicated to take some of existing classes and change to redis...
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 17, 2023, 06:32:11 PM
It does not look to be complicated to take some of existing classes and change to redis...

Well, you know all that. I don't. It would nice to have that in the future and redis is very popular. I use it with Wordpress and works great. You can also use a different db for each site in the same instance of Redis (WP_REDIS_DATABASE), usfull for people like me hosting 3-4 sites in the same plan.

Thank you !
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 17, 2023, 06:55:16 PM
Will check it out and send you something for testing
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 17, 2023, 07:16:38 PM
Will check it out and send you something for testing

Sure, any time. thank you
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 18, 2023, 01:43:59 PM
Change file extension to php, then you upload file to oc-includes/osclass/core/caches/

And then define in config one of options.

Code: [Select]
// define('OSC_CACHE', 'redis');
// $_cache_config[] = array('default_host' => '127.0.0.1', 'default_port' => 6379, 'default_password' => '');  // TCP option
// $_cache_config[] = array('default_host' => '/usr/local/var/run/redis.sock', 'default_port' => -1, 'default_password' => '');  // Unix socket option

Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 02:26:04 PM
Change file extension to php, then you upload file to oc-includes/osclass/core/caches/

And then define in config one of options.

Code: [Select]
// define('OSC_CACHE', 'redis');
// $_cache_config[] = array('default_host' => '127.0.0.1', 'default_port' => 6379, 'default_password' => '');  // TCP option
// $_cache_config[] = array('default_host' => '/usr/local/var/run/redis.sock', 'default_port' => -1, 'default_password' => '');  // Unix socket option


I will, just give me this weekend.
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 05:26:49 PM
Password for Redis? I think this is not correct.

Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 18, 2023, 05:34:36 PM
https://www.digitalocean.com/community/tutorials/how-to-set-up-redis-as-a-cache-for-mysql-with-php-on-ubuntu-20-04
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 05:43:07 PM
https://www.digitalocean.com/community/tutorials/how-to-set-up-redis-as-a-cache-for-mysql-with-php-on-ubuntu-20-04

Well, i don't have that in Wordpress and just got a reply from my hoster that it is not needed.

So, i can't help on this and my setup apparently.

Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 05:56:13 PM
I was told that we use something like this for Cpanel, so no auth is needed and the data is only for the user of Cpanel and the sites in that plan/user.


Quote
Autom8Redis automates the start/stop of a private Redis instance for each user, which can be managed by the user from his cPanel UI. This private Redis instance is only available to the user using Unix Domain Socket under his home directory and is therefore secure This private Redis daemon will run under the user/group credentials and the max memory of this Redis instance can be set according to the cPanel hosting plan for the user.
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 18, 2023, 06:07:49 PM
Just remove that auth line and thats it
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 06:26:16 PM
Just remove that auth line and thats it

You mean line 270

Code: [Select]
$this->_redis->auth($_config['password']);
??
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 06:48:17 PM
Some issues, one of them when i view ANY category.

Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 18, 2023, 10:35:57 PM
Just remove that auth line and thats it

You mean line 270

Code: [Select]
$this->_redis->auth($_config['password']);
??

Yes.

Some issues, one of them when i view ANY category.

Hard to help. Something in error log?
Title: Re: Memcache(d) Questions and Issues
Post by: dsf on January 18, 2023, 10:38:08 PM
The errors are from debug.log i posted above. No see nowhere any other errors.
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 24, 2023, 09:34:19 AM
Probably some issue with cache.
It was not false, so was found, but not valid.
Try to go to that cache file and find:
Code: [Select]
      if(NULL === $value) {

replace with:
Code: [Select]
      if(false === $value) {
Title: Re: Memcache(d) Questions and Issues
Post by: MB Themes on January 24, 2023, 09:34:30 AM
To disable password when not entered or empty, change this:
Code: [Select]
      $this->_redis->auth($_config['password']);

into this:
Code: [Select]
      if($_config['password'] != '') {
        $this->_redis->auth($_config['password']);
      }