Hi there,
I run the latest Drupal 7 using Perusio's Nginx configuration. I used to use Filecache a long time ago on Drupal 6 with Perusio + Nginx and the cache_backport module. Now I'm evaluating it again for my site now that I'm on Drupal 7. But something isn't working, and I suspect it has something to do with the fact that I'm using Nginx.
I tried the default config for non-Apache sites:
$conf['cache_backends'] = array('sites/all/modules/filecache/filecache.inc');
$conf['cache_default_class'] = 'DrupalFileCache';
$conf['filecache_directory'] = '/tmp/drupal/filecache';
But this doesn't work at all. It still complains on the status page: "No File Cache setup in" my settings.php.
So I tried changing the filecache_directory to '/srv/www/filecache' (my Drupal is in '/srv/www/drupal'). This doesn't get rid of the "No File Cache setup in..." message. It also doesn't immediately populate the specified the changed filecache_directory until I uninstall and re-install the filecache module. And when it does finally populate it, it only generates about 66 files and doesn't seem to update them. These are the directories created inside '/srv/www/filecache' :
sites_mysite_cache
sites_mysite_cache_field
sites_mysite_filecache_bins
sites_mysite_cache_bootstrap
sites_mysite_cache_rules
So for some reason it's not caching 'cache_page' or 'cache_content', which is the main reason I want to use filecache.
Any idea what's going wrong? Thanks.
Comments
Comment #2
ogi CreditAttribution: ogi commentedThese problems suggest that there is something not right in
settings.php
. Could you post the result ofgrep cache_ settings.php
? Can you also confirm thatfilecache
is installed insites/all/modules
and so the reference tosites/all/modules/filecache/filecache.inc
is correct?Comment #3
ogi CreditAttribution: ogi commentedComment #4
rahim123 CreditAttribution: rahim123 commentedHi ogi, thanks a lot for taking the time to respond.
I also read somewhere that the issue could be caused by some other configuration in settings.php that rewrites the $conf array. I checked for that, and only found these lines:
I don't think that should affect anything, and at any rate I tried placing the filecache conf before the 404 $conf, and it made no difference.
I also tried the previous 7.x-1.0-beta4 version, and it had the same problem. (The only difference was that there were something like 64 files all in the same level of the cache directory, per the previous design of the module.)
Comment #5
rahim123 CreditAttribution: rahim123 commentedHmm, this is interesting. After a few minutes some additional bins appeared:
Notice that everything is being created as root:root (initially the /tmp/drupal/filecache/ directory got created as root:root and I recursively chown'ed it to nginx:nginx .
Both the nginx worker processes and the php-fpm threads run as user 'nginx'. Only the master nginx controller process runs as root, and I believe it has to be that way:
So I suspect it might actually be working, at least for those cache bins. But why is the Status page still complaining? And why won't it create the cache_page or cache_content bins? I even tried explicitly adding them to settings.php:
Comment #6
ogi CreditAttribution: ogi commentedHow do you run cron? Is it run as root by PHP CLI? Is /tmp/drupal/filecache chown nginx:nginx?
Comment #7
rahim123 CreditAttribution: rahim123 commentedI use drush with Elysia cron
I was actually just about to post an issue with cron. When I try to manually run filecache_cron from the Elysia interface it gives out an ugly error page:
Regarding permissions:
Comment #8
rahim123 CreditAttribution: rahim123 commentedCould it have something to do with pathnames relative to the Drupal root in $conf['cache_backends'] , whereas it's an absolute filesystem pathname in $conf['filecache_directory'] ?
Comment #9
ogi CreditAttribution: ogi commentedIf you have have POSIX ACL activated (probably yes), please run
setfacl -R -m d:u:nginx:rwx -m u:nginx:rwx /tmp/drupal/filecache
. Then please replace filecache module directory with https://www.drupal.org/project/filecache/releases/7.x-1.x-dev . Hopefully this wil fix all your issues :-)Comment #10
rahim123 CreditAttribution: rahim123 commentedThanks a lot for the fast response! I made both of those changes, but I'm not having any luck. The
setfacl
command didn't give any errors, but I wonder if my filesystem isn't mounted with ACL support? It's XFS, so I'm not sure how to check.EDIT: Appears to always be enabled by default for XFS:
http://oss.sgi.com/archives/xfs/2009-12/msg00020.html
And what about the parent /tmp/drupal dir? Does it need any special permissions?
Comment #11
ogi CreditAttribution: ogi commentedI will add checks in the status page and I will write here when it's ready for testing. Does the status page work now after updating to latest dev version?
Comment #12
rahim123 CreditAttribution: rahim123 commentedNo, it says:
And any idea why the cron fails with an error, and why the cache_class_cache_content and cache_class_cache_page bins aren't getting handled by Filecache?
Thanks again for your time.
Comment #13
ogi CreditAttribution: ogi commentedIt looks like permission problem because cron is run as root and files and directories are created with owner root and cannot be modified by
nginx
user.setfacl
should fix this and I'm surprised that it doesn't. Anyway, the status page should check for these permission problems and this is what I'm going to do.Please confirm that the
filecache_registry_pathname
cron error is fixed in dev version.I guessed that
/tmp/drupal/cache
is owned by root and nginx filecache cannot create thecache_page
directory but it doesn't seem the case. Just in case, could you check if anonymous page caching is activated in/admin/config/development/performance
and lifetimes and expire are set?Comment #14
rahim123 CreditAttribution: rahim123 commentedHi again,
The cron error continues the same:
Anonymous page caching is activated, but there is no lifetime or expiration configured. In my experience with other caching mechanisms such as Redis and Memcache the
cache_class_cache_content
andcache_class_cache_page
bins still get created with these same settings.Comment #15
ogi CreditAttribution: ogi commentedIt seems that
sites/all/modules/filecache
is not the dev version from https://www.drupal.org/project/filecache/releases/7.x-1.x-dev . In the dev version, line 23 is empty line.Comment #16
rahim123 CreditAttribution: rahim123 commentedHuh, you're right. That's really weird. I don't know where Elysia is getting that from. Just to be sure, I deleted and re-installed the filecache directory from the dev version you specified. Then I un-installed the filecache module and removed its config from the database. At that point Elysia cron had no filecache entry. Then I re-installed filecache and tried to run the cron entry, and it still shows me the same line 23 error. I confirm that it is indeed an empty line:
Comment #17
ogi CreditAttribution: ogi commentedCould you do one more test about
cache_page
? Just to be sure, as anonymous user (e.g. private browser mode) go to some pages that should be cached. Then look ifsites_mysite.com_cache_page
is created and if there are the cached pages. If not, look atsites_mysite.com_filecache_bins
- it should contain all cache bins that filecache handles.I will make changes to the documentation about the permission problems. The correct solution is to use
sudo -u nginx drush ...
for all cache- and cron-related commands.Comment #18
rahim123 CreditAttribution: rahim123 commentedNo, they're definitely not getting created. This is on a high traffic site, so constant anonymous hits.
This is the content of
Comment #19
rahim123 CreditAttribution: rahim123 commentedOK, partially figured out it out. Looks like my PHP opcache had the old version of the filecache module. After rebooting the entire server I remembered about that. Really sorry about the red herring / wild good chase. Anyway, the status page now works:
And the filecache cron job now works as well.
However, it still isn't creating cache_page or cache_content bins.
Comment #20
rahim123 CreditAttribution: rahim123 commentedAfter running the cron job again the Status page now shows:
But Linux says otherwise:
Comment #21
rahim123 CreditAttribution: rahim123 commentedOK, I think I tentatively have it figured out: I moved the
filecache_directory
to/srv/www/filecache
, which is owned nginx:nginx and has 700 perms.Now, it shows all these bins, which continue to grow in size:
Both the Status page and
du -sh /srv/www/filecache
report about the same size on disk after running the cron job, and it quickly grows into the hundreds of MB. Look OK?Comment #23
ogi CreditAttribution: ogi commentedIt looks like the issue is solved but please don't close it. I'll make various changes related to it (permission checks in status page and updated README.txt).
I found references about
cache_content
in Drupal 6 modules but not in Drupal 7 modules, so it looks like there is no such cache bin in D7.Comment #24
rahim123 CreditAttribution: rahim123 commentedCool, thanks for updating this module, it's much appreciated.
It looks like filecache/sites_mysite.com_cache_bootstrap/hook_info is occasionally getting re-owned to root:root, probably after the cron job runs. If I relax the permissions to /srv/www/filecache would you see any problems with security? I'm the only user on this box, and the nginx server doesn't allow direct access to the filecache dir.
Comment #25
ogi CreditAttribution: ogi commentedAlso, the expire of
cache_page
isCACHE_TEMPORARY
and ifcache_lifetime
is 0, it always gets deleted in cron runs by filecache. Consider changingcache_lifetime
in/admin/config/development/performance
it to some time value of your choice. It is something that needs mentioning inREADME.txt
Comment #26
ogi CreditAttribution: ogi commentedThe
setfacl
solution from above should work, in theory, especially now that filecache directory is not in/tmp
and will not be wiped out in the next restart.You can change
FILECACHE_DIRECTORY_MODE
andFILECACHE_FILE_MODE
infilecache.inc
to 0777 and 0666. Of course, it will get overriden by next update, so you have to watch out :-)Comment #27
rahim123 CreditAttribution: rahim123 commentedAh, that's good to know about the cache_page lifetime. But if a node gets updated or a new comment is added, will it invalidate the cache? Or would anonymous users have to wait until the cache lifetime is passed before seeing updates?
Comment #28
ogi CreditAttribution: ogi commentedThe
CACHE_TEMPORARY
logic from above is specific for File Cache.Now I see that cache_clear_all should clear
cache_page
and this needs to be added to filecache because it's called in many places, e.g. saving comment.Comment #29
ogi CreditAttribution: ogi commentedFortunately, no need to add it to File Cache. Core's
cache_clear_all
is what is called everywhere and after cleaningcache_page
it calls the specific cache implementation :-)Comment #30
rahim123 CreditAttribution: rahim123 commentedSo the specific permission error I'm getting is:
I did run your suggestion of:
Any other ideas? Thanks a ton.
Comment #31
rahim123 CreditAttribution: rahim123 commentedAh, I see. But that would clear the entire cache_page bin? Or just the entry for that page? Since my site is a high write-traffic forum it wouldn't do much good if my cache is wiped every 30 seconds when somebody posts a comment.
Comment #32
ogi CreditAttribution: ogi commentedI was not entirely correct.
cache_clear_all
callscache_page
's clear(NULL, FALSE) and this deletes only "expired" pages. If cache lifetime is 0 (none), cached pages will be deleted immediately. If cache lifetime is non-zero, this is the duration for the cached pages to be allowed to be staled. The logic in File Cache is the same as in DrupalDatabaseCache::clearComment #33
ogi CreditAttribution: ogi commentedSince your site is forum, cached pages may get deleted too often. If cache lifetime is non-zero, you risk confusing users by showing them cached pages without their just-written comment.
Comment #34
rahim123 CreditAttribution: rahim123 commentedRight, but that would only happen if they post and then immediately log out, correct? Because only anonymous users will hit the cached pages?
Comment #35
ogi CreditAttribution: ogi commented(It's becoming like brainstorming but) it looks like it's OK for non-zero cache lifetime because it's used only for anonymous users, the comment author will immediately see his/her comment, just the anonymous users may see it delayed with the specified cache lifetime delay or more (
cache_clear_all
, cron, or something else should clearcache_page
so that anonymous users to see updated content).Comment #36
ogi CreditAttribution: ogi commentedThe way I read the code, the exact logic when cache lifetime is non-zero is the following:
1. comment is added
2. cache_clear_all is called
3. topic page is protected in the cache because of non-zero cache lifetime, so it's not deleted
4. for the duration of cache lifetime, cache_clear_all doesn't delete the cached topic page
5. after cache lifetime is passed, the cached page is not deleted immediately
6. any cache_clear_all (any new comment anywhere) will delete the page, so it's possible that the cached topic page will not get deleted until cron, if noone calls cache_clear_all meanwhile
Comment #40
ogi CreditAttribution: ogi commentedPermission checks and documentation are much simplified and improved in beta6.