Question

I set up a metadata cache in Zend Framework because a lot of DESCRIBE queries were executed and it affected the performances.

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

I can indeed see the cache files created, and the website works great.

However, when I launch unit tests, or a script of the same application that perform DB queries, I end up with an error because Zend couldn't read the cache files.

This is because in the website, the cache files are created by the www user, and when I run phpunit or a script, it tries to read them with my user and it fails.

Do you see any solution to that? I have some quickfix ideas but I'm looking for a good/stable solution. And I'd rather avoid running phpunit or the scripts as www if possible (for practical reasons).

Was it helpful?

Solution

try sudo command. something like this $sudo -u www php -f run-tests.php

edit

maybe

$backendOptions = array ('cache_dir' => CACHE_PATH . '/db-tables-metadata', 'cache_file_umask' => 0755, 'cache_file_perm' => 0755);

OTHER TIPS

Do you want cached table metadata during unit testing? I'd normally disable that cache in development/testing.

You can try adding your test user to the www group (usermod -a -G www testuser).

Chances are that the cache files have standard 644 permissions which means your user still won't be able to modify the files, but if you set the permissions on the cache directory to 777 during testing then you should be able to write new files to that directory.

If you run PHP using CGI/FastCGI, you can have PHP run as your user rather than the generic www user. Or if you are using an Apache module, mod_suphp will allow you to run PHP as your user as well.

Sorry its not too much help but hopefully can give you some more ideas..

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 .

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