Framework Version: 3.1.5
I am having some issues with the flush procedure when alternating between flushing via the browser/URL (i.e. http://www.example.com/?flush=all) and flushing via the command line (i.e. php /var/www/html/example-www/framework/cli-script.php / flush=all)
To provide a bit of background, there are two servers involved (both managed by a third party) one for a staging environment (where I push my code and CMS users update the CMS) and one for the live externally visible website. A synchronisation process is carried out to copy the codebase and database from stage -> live and the CLI based flush is done as the last step of this process.
The problem is that on a number of occasions I have noticed behaviour that suggests that the CLI based flush is doing nothing at all i.e the live website has errors on certain pages which are resolved by me manually doing a flush=all via the URL.
I have been digging into the core code quite extensively to try and work out why this would be. I understand that a new sub-folder of silverstripe-cache/ is created for each 'user' which causes cache to be generated (as per the getTempFolderUsername() function in TempPath.php). From my testing regardless of wether I flush via the URL or CLI the 'user' is determined to be 'root' however, there are differences in the directories permissions, owner and group depending on which method I use:
Browser/URL Flush:
Dir = root
Perms = 755
Owner = apache
Group = apache
Command Line Flush:
Dir = root
Perms = 775
Owner = root
Group = root
This subfolder is created in the getTempFolder() function in TempPath.php but its permissions are never explicitly set.
I can see that there is some logic on the parent cache folder (silverstripe-cache) in the getTempParentFolder() function in TempPath.php to ensure that it has full read/write/execute permissions:
// first, try finding a silverstripe-cache dir built off the base path
$tempPath = $base . DIRECTORY_SEPARATOR . 'silverstripe-cache';
if(@file_exists($tempPath)) {
if((fileperms($tempPath) & 0777) != 0777) {
@chmod($tempPath, 0777);
}
return $tempPath;
}
However I have a couple of problems with this, 1) what is this portion of the if() condition meant to say/do
(fileperms($tempPath) & 0777)
and 2) from my testing this code doesnt work? I can set my silverstripe-cache/ directory perms to 555, do a dev/build, a flush=all and anything else yet the silverstripe-cache/ dir's permissions never change?
Either way I can see no logic to do the same 'permissions fixing' on any of the sub-folder e.g. silverstripe-cache/root/ or silverstripe-cache/apache/ etc and these are the directories which are getting all the cache files written to?
I have a couple of questions:
- Is this a bug
- are other people suffering the same issue
- Is there anyway I can force there to be 1 cache file which is used by all 'users' which would remove the issue?
Thanks in advance,
HARVS1789UK