-
-
Notifications
You must be signed in to change notification settings - Fork 454
clear() wipes out other files #362
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Hi, You have to setup an absolute path for the cache, relative path are not recommended at all because it depend how the webserver set up the working directory. Cheers, |
I'm closing ticket, do not hesitate to reopen it if the bug persists. Cheers, Georges |
Ok. I've changed my path to sys_get_temp_dir()."/cache", which translates to something like:
I set the cache var:
The first time I run the script, the data gets cached in this dir, as expected. Then I add clear() to see whether it works:
The cache in the above dir does appear to be cleared, but my browser returns the following error (below). Presumably I need to adjust permissions someplace, but I'm not sure where or why. Fatal error: Uncaught exception 'phpFastCache\Exceptions\phpFastCacheDriverException' with message 'PLEASE CHMOD - 511 OR ANY WRITABLE PERMISSION!' in /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/PathSeekerTrait.php:159 Stack trace: #0 /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(117): phpFastCache\Drivers\Files\Driver->getFilePath('news') #1 /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php(57): phpFastCache\Drivers\Files\Driver->driverRead(Object(phpFastCache\Drivers\Files\Item)) #2 /www/apache/html/uw_home_redesign/public/index.php(39): phpFastCache\Core\DriverAbstract->getItem('news') #3 {main} thrown in /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/PathSeekerTrait.php on line 159 |
You may need to chmod the target directory in 0777 |
I did change the permissions as suggested. No matter which dir I designate as the target directory ("path") in config; e.g., [site-root[/cache, clear() deletes the cache directory itself and all of it's contents. I would expect the contents to be gone, but the directory should remain, yes? Once it's gone, the permissions are irrelevant, because the directory no longer exists. It feels like a Catch 22. I'm not sure what I might be doing wrong here. |
Yeah the directory is deleted this is a purpose to make sure that all files are being deleted. |
Composer says v5.0.9. So I take it that the target directory must be embedded within another writable directory.... I can try that. |
Also if your system temp dir is not writable by default there is maybe a huge configuration issue on your server !! |
I'm just working in my local development environment. I have full control over the permissions. I just changed my $config to a subdirectory within the site root:
where storage (and all of its contents) is writable:
The exact same thing happened as before when I ran clear(), except that the storage directory is still there (one small victory): Fatal error: Uncaught exception 'phpFastCache\Exceptions\phpFastCacheDriverException' with message 'PLEASE CHMOD - 511 OR ANY WRITABLE PERMISSION!' in /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/PathSeekerTrait.php:159 Stack trace: #0 /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Drivers/Files/Driver.php(117): phpFastCache\Drivers\Files\Driver->getFilePath('news') #1 /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/StandardPsr6StructureTrait.php(57): phpFastCache\Drivers\Files\Driver->driverRead(Object(phpFastCache\Drivers\Files\Item)) #2 /www/apache/html/uw_home_redesign/public/index.php(39): phpFastCache\Core\DriverAbstract->getItem('news') #3 {main} thrown in /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Core/PathSeekerTrait.php on line 159 It should be getting the path correctly; otherwise it wouldn't be able to write the cache in the first place. Somehow the getFilePath method in PathSeekerTrait.php is either getting the wrong path, thinks it's not writeable, or....I don't know what. There's a disconnect somewhere. |
The Chmod is maybe not the only one issue, is the Webserver running under the same user ? |
PHP is running with me as the user (remember, this is just a dev environment). All of these directories need to be owned by me. If I change the owner to _www then phpfastcache complains that FIles is configured incorrectly. If PathSeekerTrait.php thinks that there's still a directory that still needs to be made writeable, there must be a way to tell which one it complaining about. |
In that case I don't know where the issue is from, this is maybe env-dev specific but I am currently not able to reproduce this issue. Since the Files driver is the most used, i think that a lot of people would reported the issue before :'( |
/www/apache/html/uw_home_redesign/storage/cache <-- you need cache is writeable , not storage. |
I appreciate everyone's patience to stick with me here. As I explained above, I can set permissions to cache to 0777 or anything else, but once it gets deleted, it's permissions are no longer relevant. When I run clear(), the error appears even when cache is writeable. In trying to debug this, what is getFilePath() in PathSeekerTrait.php trying to do when it is trying to write something? clear() deletes the entire cache directory, but the $path variable it is testing is: /www/apache/html/uw_home_redesign/storage/cache/localhost_8002/files/50 which contained the actual cached text file. But that directory and file already have been deleted by clear(). So what's supposed to be going on here? |
I think I may have figured it out, or at least have a workaround. I realize that what I was testing was an artificial situation, so I just inserting cache->clear() as described above. The code that follows essentially checks to see whether anything is in the cache, and either retrieve it or save some new data to the cache. What I had to do is clear or reset $cache within this block; e.g.:
Then the problem goes away. I suspected something like this was going on a little while ago, but it took me a little time to think through it. I should have seen it sooner. Phew. In this project, the clear() method likely will live in a separate script (triggered by a url request), and will not be commingled with the script that writes to the cache. Thanks Geolim4 and others for hanging with me. |
Fine then, |
I've been working with phpfastcache for only a short time. I'm using the Files driver and my config look like this:
phpfastcache is creating and saving the cache just as I want it to. Apparently the default location is in a directory at the root level named [hostname]/files.
But if I run $cache->clear(), the cache directory is completely removed. Moreover, several other (very important) files at the root level get wiped out, including my composer.json and Gruntifile.js. The browser displays a warning:
Warning: unlink(): No such file or directory in /www/apache/html/uw_home_redesign/vendor/phpfastcache/phpfastcache/src/phpFastCache/Util/Directory.php on line 102
How can I set this up so that the cache gets cleared and all of my other files remain untouched?
The text was updated successfully, but these errors were encountered: