3

我在 Zend Framework中设置了元数据缓存,因为执行了很多DESCRIBE查询并影响了性能。

$frontendOptions = array ('automatic_serialization' => true);
$backendOptions = array ('cache_dir' => CACHE_PATH . '/db-tables-metadata');
$cache = Zend_Cache::factory(
    'Core',
    'File',
    $frontendOptions,
    $backendOptions
);
Zend_Db_Table::setDefaultMetadataCache($cache);

我确实可以看到创建的缓存文件,并且网站运行良好。

但是,当我启动单元测试或执行数据库查询的同一应用程序的脚本时,我最终会遇到错误,因为Zend 无法读取缓存文件

这是因为在网站中,缓存文件是由 www 用户创建的,当我运行 phpunit 或脚本时,它会尝试用我的用户读取它们,但它失败了

你有什么解决办法吗?我有一些快速修复的想法,但我正在寻找一个好的/稳定的解决方案。而且我宁愿www尽可能避免运行 phpunit 或脚本(出于实际原因)。

4

3 回答 3

1

试试sudo命令。像这样的东西$sudo -u www php -f run-tests.php

编辑

也许

$backendOptions = array ('cache_dir' => CACHE_PATH . '/db-tables-metadata', 'cache_file_umask' => 0755, 'cache_file_perm' => 0755);
于 2012-09-03T10:52:49.787 回答
1

你想在单元测试期间缓存表元数据吗?我通常会在开发/测试中禁用该缓存。

您可以尝试将您的测试用户添加到www组 ( usermod -a -G www testuser)。

缓存文件可能具有标准644权限,这意味着您的用户仍然无法修改文件,但如果您777在测试期间将缓存目录的权限设置为,那么您应该能够将新文件写入该目录。

如果您使用 CGI/FastCGI 运行 PHP,您可以让 PHP 作为您的用户而不是通用www用户运行。或者,如果您使用的是 Apache 模块,mod_suphp也将允许您以用户身份运行 PHP。

对不起,它没有太多帮助,但希望能给你更多的想法..

于 2012-08-12T18:38:21.760 回答
-1

I had a problem of similar kind Later i could find that , Since I was running several other application server cache was getting clashed meaning two applications were using same cache , try naming the cacheobject for all types

and Also if you want you can also configure App.php file to create a different cache file for unit testing , This is a usual problem which occurs in shared hosting .

于 2012-09-04T17:12:31.523 回答