本文介绍了使用CakePHP文档根奇怪的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这里是一个新的给我。

这里的情况...我有一个蛋糕的应用程序在多个环境下运行(开发,QA​​,分期,住),使用Git管理。

我发展走在我的开发分支,并从dev.BLAH.com访问该分支。
DEV供应/var/www/dev.BLAH.com/app出

有时,在DEV工作时,我开始越来越象这样的错误:

 警告(512):型号锻炼是不是与模型ExerciseOutcome[/var/www/QA.BLAH.com/lib/Cake/Model/Behavior/ContainableBehavior相关.PHP,线344]

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! ;)

解决方案

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.

这篇关于使用CakePHP文档根奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 11:31
查看更多