Comments (26)
@stamster Great!
Let me know if you need any input/data or anything that i can test here!
Thank you!
Alan
from phalcon.
I'm sorry I haven't had time to get onto this. I'm still willing and able though - so I'll try to reproduce it ASAP.
I'll bring on my findings for sure :)
from phalcon.
No one knows about this problem?
It just happens when using modelsManager or Model::find and derivatives
Thanks
Alan
from phalcon.
Hmm, are you sure you've set up two separate memcached daemons? Or you're using the same daemon with multiple ports?
What keys you're using? I believe all default ones.
The thing is, using Libmemcached
as an adapter you can set:
- in client array:
Memcached::OPT_PREFIX_KEY => 'orm.' //this is the DOMAIN!
- in servers array:
'prefix' => 'model_' //actual prefix of the keys
That way you can use the same memcached instance with different keys/domains in order to distinguish across shared apps/services.
That's what I'm using for Models' metadata, regular sessions and shopping cart sessions.
Also check your Opcache. Try disabling it for a test. If all is good with your memcached setup, then it might be that Opcache is the culprit as you have two files with a same variable name - $config
.
P.S. You should also take into account modelsMetadata
service, and use \Phalcon\Mvc\Model\Metadata\Libmemcached
as adapter if you want to override default in memory cache.
from phalcon.
Hello @stamster
I'm using Memcached for Sessions + cache db data also.
I've already tried using prefix and only one memcached instance, but in the end it had the same issue of using the key without the prefix sometimes.
I've set a debug so that i know if its using the right port when using website2 and i'm sure it's setting it right.
[root@memcache ~]# ps ax | grep mem
8262 pts/0 S+ 0:00 grep mem
15190 ? Ssl 2133:32 /usr/local/bin/memcached -d -p 12111 -u memcached -m 65392 -c 200000 -P /var/run/memcached/memcached.pid -l 0.0.0.0 -t 4
15423 ? Ssl 0:13 /usr/local/bin/memcached -d -p 12112 -u memcached -m 16384 -c 200000 -P /var/run/memcached/memcached.pid -l 0.0.0.0 -t 4
We are not using opcache.
I'm also using:
$di->setShared('modelsMetadata', function () use ($config) {
$metaData = new Phalcon\Mvc\Model\Metadata\Libmemcached(
array(
"servers" => array(
array(
'host' => $config->memcache->host,
'port' => $config->memcache->port,
'weight' => 1
),
),
"client" => array(Memcached::OPT_HASH => Memcached::HASH_MD5),
"lifetime" => 3600
)
);
return $metaData;
});
With 2 distinct memcached instances i don't need to use prefix.
Thanks for your help but can you think in anything else?
Thanks
Alan
from phalcon.
Ahh, now I see.
Try with this.
On your both service definitions using (lib)memcached, set this in servers array:
'statsKey' => null //This is MANDATORY to be defined as null or empty string
Restart memcached and your app server.
P.S. why aren't you using Opcache?! Are you sure about that - it should be enabled by default. Only if you wanted to disable it.... but I don't see a reason.
from phalcon.
@stamster,
I've modified for this:
$di->setShared('modelsCache', function () use ($config) {
//Cache data for one day by default
$frontCache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime" => 600
));
$cache = new Phalcon\Cache\Backend\Libmemcached($frontCache, array(
'servers' => array(
array('host' => $config->memcache->host,
'port' => $config->memcache->port,
'weight' => 1
),
'statsKey' => null //This is MANDATORY to be defined as null or empty string
),
'client' => array(
Memcached::OPT_HASH => Memcached::HASH_MD5,
Memcached::OPT_PREFIX_KEY => $config->memcache->prefix,
)
));
return $cache;
});
what do you mean by restart my app server?
What does statsKey null should do? because checking in Phalcon docs is written:
Note: statsKey has a negative performance impact
PS: I've double checked in phpinfo and php -i (web and cli) for opcache and also for any entries in our php.ini and found nothing of opcache neither enabled or disabled.
from phalcon.
I've went ahead and done that restarted both memcached and the same thing :/
from phalcon.
statsKey
used to force default _PHCM
prefix in previous 2.0.x series of Phalcon, so that's why I'm used to setting it to null just to make sure. Now it should default to empty string, so that does not seem to be culprit in your case after all.
So you don't use Opcache module at all, "good" in this scenario, bad for production.
Take a look at this example:
https://olddocs.phalconphp.com/en/latest/api/Phalcon_Cache_Backend_Libmemcached.html
A prefix that is automatically perpended to the cache keys
Last but not least -
show actual keys stored in Memcached (in your case you need to double this code as you have two memcached instances running:
$m = new \Memcached('testingSrv1');
if (!count($m->getServerList())) {
$m->addServer('hostname1', 11211, 1);
}
$keys = $m->getAllKeys();
print_r($keys);
// ########################
$m = new \Memcached('testingSrv2');
if (!count($m->getServerList())) {
$m->addServer('hostname2', 11211, 1);
}
$keys = $m->getAllKeys();
print_r($keys);
from phalcon.
@stamster
I use phpMemcachedAdmin to check the keys,
They are stored right in both servers (checked it).
The problem is when reading something already stored it failsback to the one that already has a cache of that key (11211 has and 11212 does not, so 11212 ask for the cache and it finds in 11211 and shows it altough it does not have the key).
It also happened the same when used prefix, it ignored the prefix and got the key without prefix because it existed.
This bug is really driving me crazy I've already tried everything in the last 2 months and now i'm almost sure that's a bug and not a misconfig.
I'm almost sure the configuration is correct and should work as planned.
If you have any mor thoughts that we can do to solve this it'd be great to hear!!
Thanks
Alan
from phalcon.
I'll try to reproduce such behavior with setup of two memcached instances.
I think of one issue with your conception, but as I'm not sure let's not put it onto table ATM.
from phalcon.
@stamster
Hello, were you able to set up this enviroment?
Thanks
Alan
from phalcon.
Great! Thanks :)
from phalcon.
Hello @stamster,
Do you have any good news regarding this issue? 😺
from phalcon.
Hello Guys,
Anyone else has any insight for this issue?
We are depending on this to lauch the new MultiLanguage website :)
If anyone has any inputs it will help!
Thanks
Alan
from phalcon.
Another example if I try to:
$var= Model::query()
->columns("XXXXX")
->where("XXX = Y")
->cache(array("key" => "somekey","lifetime" => 200))
->execute();
It brings the results from the key stored in the instance 12111 if i remove the cache line it brings me the result in the right database. Checking in the instance 11212 the key does not exists.
With phpmemcachedadmin everything works as expected and i can write and read from different caches.
Hope this will bring some other insights..
Thanks
Alan
from phalcon.
i was also having this issue and i believe it is related to persistence_id when creating a libmemcache instance, if undefined, phalcon will automatically create the instance with persistence_id = "phalcon_cache" (or "phalcon-session" when using session adapter) i set "persistent_id" = "" (or define one if you which to use persistence) in config and this seems to fix my issue, you can do this for sessions also
from phalcon.
@Nialld i dont think it's related to persistence_id
, i have two projects with different memcached servers , and with different persistence_id
, but still got same issue.
from phalcon.
@atrope @Nialld do both of you have solutions? :)
from phalcon.
@nevernet sorry missed your question, can i see your config... i had to set this in both the session cache section and also the general cache section of my config... i have one config for storing session data and one for general data caching, after i set this option the problem stopped happening for me
from phalcon.
I was reading through this and want to ensure that the issue still persists before trying to reproduce it and fix it. Do you guys have a chance to test this with v4?
from phalcon.
@niden sorry, i am still working on v3. when i have a chance i will review it with v4.
thank you
from phalcon.
@nevernet Not a problem. Take your time
from phalcon.
@niden ive been porting our app over to v4 and cant get libmemcached session adapter to work at all. I have switched to stream adapter to move on, the data i set in my libmemcached session is not saving. are there know issues with using memcached as an engine for storing session data in V4?
from phalcon.
@Nialld We don't have any reports regarding libmemcached
at the moment. Do you have some code and environment info for us to reproduce your issue? Any error messages?
from phalcon.
Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalcon.io/post/github-closing-old-issues
from phalcon.
Related Issues (20)
- [NFR]: Replace regexp in the router with arrays for extra performance
- Can't access page, 404 FORBIDDEN
- Can I use `$this->getRelated` on already cached data?
- [BUG]: Scrutinizer Fixes HOT 1
- [NFR]: ADD sticky for read write connection
- [NFR]: removeBehavior method in Model
- [NFR]:returnedValue not updated after dispatcher->forward
- [NFR]: No way to add html attributes to Select Tag. documentation inadequate HOT 1
- [BUG]: The "setDefault" method does not work for forms of type "text" with name "value" HOT 5
- update src folder links
- How to use cookie in phalcon 4.x ? HOT 1
- update tests folder links
- [NFR]: Complete rework of ORM HOT 3
- [BUG]: \Phalcon\Encryption\Crypt + named parameters/arguments throw fatal error. HOT 1
- [NFR]: Refactor Phalcon\Mvc\Router/Route HOT 1
- [NFR]: Refactor Phalcon\Mvc\Model\MetaData
- phalcon 3,4 webhook problem HOT 2
- [NFR]: What is the purpose of this library? HOT 3
- [NFR]: Add a getResult() or fetchAll() method to Resultset\Simple
- [BUG]: when i use JWT Builder , api returns blank HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phalcon.