Question

Ok, here's a new one to me.

Here's the situation... I have a Cake app running under multiple environments (dev, qa, staging, live), managed using GIT.

I'm developing away on my development branch, and access that branch from dev.BLAH.com. DEV is served out of /var/www/dev.BLAH.com/app

Occasionally, when working on DEV I start getting errors like this:

Warning (512): Model "Exercise" is not associated with model "ExerciseOutcome" [/var/www/QA.BLAH.com/lib/Cake/Model/Behavior/ContainableBehavior.php, line 344]

NOTE: That error is caused because it is trying to find an association that is not built yet under the QA environment, so it's not about the missing association, it's about the WRONG PATH.

Clearly, for some unknown reason, the DEV domain is trying to serve files from the QA domain! Now, I don't think this is related to some kind of human coding error, because the simple FIX for it is to restart Apache!

Now, I thought it might be some kind of session issue, because I'm storing sessions in the DB, but even if I clear all the sessions in the DB (without restarting apache), it doesn't fix it.

But if I restart Apache, leaving the sessions table untouched, it suddenly starts working again!

It all seems so strange to me, that I just don't know where else to look. I tried changing the various levels of caching, but that didn't change anything.

I don't think I'm an idiot, but I hope someone can prove me wrong! ;)

Was it helpful?

Solution

As noted in the comments, the issue is most likely to do with APC and prefixes.

What happens is that Cake caches the paths of various models using APC. This is all fine until you have multiple applications that use the same cache data on the one server. This is why Cake allows you to set the prefix of the cache.

So one solution is to set the prefix in a per-deployoment basis, like this:

// Prefix each application on the same server with a different string, to avoid Memcache and APC conflicts.
$prefix = 'myapp_DEV_';

However, this gets messy when you're using source control and you want the various deployments to be as close to each other as possible.

The way I got around it was to modify the cache config in APP/Config/core.php as follows:

/**
 * Configure the cache used for general framework caching.  Path information,
 * object listings, and translation cache files are stored with this configuration.
 */
Cache::config(
    '_cake_core_',
    array(
        'engine' => $engine,
        'prefix' => $prefix . 'cake_core_' . Inflector::slug(ROOT),
        'path' => CACHE . 'persistent' . DS,
        'serialize' => ($engine === 'File'),
        'duration' => $duration
    )
);

Note the Inflector::slug(ROOT) line. This will give each application a unique prefix, without having to explicitly set it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top