使用CakePHP文档根奇怪的问题 [英] Odd issue with CakePHP Document Root

查看:116
本文介绍了使用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]


  

注意:该错误造成,因为它试图找到一个协会
  未在QA环境下尚未建立,所以它不是关于失踪的关联,它是关于在错误的道路。


显然,对于一些未知的原因,DEV域试图从QA域文件服务!现在,我不认为这是关系到一些人的编码错误的,因为它简单的解决方法是重新启动Apache!

现在,我想这可能是某种会议的问题,因为我存储在数据库会话,但即使我清楚在DB的所有会话(无需重新启动Apache的),它并没有解决它。

但是,如果我重新启动Apache,离开会议桌不动,它突然开始工作了!

这一切似乎都那么奇怪,我,我只是不知道还有什么地方可以看。
我试图改变缓存的各个层面,但这并没有改变任何东西。

我不认为我是个白痴,但我希望有人能证明我错了! ;)


解决方案

由于在评论中指出的那样,问题是最有可能与APC和prefixes做的。

什么情况是,蛋糕缓存使用APC各种型号的路径。这是所有罚款,直到你有一个使用一台服务器上相同的缓存数据的多个应用程序。这就是为什么蛋糕可以让你设置缓存的preFIX。

所以,一个解决办法是设置preFIX在每个deployoment的基础上,是这样的:

  // preFIX用不同的字符串在同一台服务器上的每个应用程序,以避免内存缓存和APC矛盾。
$preFIX ='myapp_DEV_';

不过,这当你使用源控制和你想要的各种部署,以尽量接近对方尽可能变得混乱。

我周围的方法是修改APP /配置/ core.php文件缓存的配置如下:

  / **
 *配置用于一般框架缓存缓存。路径信息,
 *对象列表,和翻译缓存文件存储与此配置。
 * /
缓存::配置(
    _cake_core_',
    阵列(
        '引擎'= GT; $引擎,
        'preFIX'=> $preFIX。 cake_core_。偏转::蛞蝓(根),
        '路径'= GT;缓存。 持续性。 DS,
        '连载'=> ($引擎===文件),
        '时间'=> $持续时间
    )
);

请注意在变形器::蛞蝓(根)行。这会使每个应用程序的唯一preFIX,而无需显式设置它。

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

解决方案

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文档根奇怪的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆