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).
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);
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With