How to fix “touch(): Utime failed: Operation not permitted” on saving cache with symfony?

后端 未结 2 1934
南笙
南笙 2020-12-22 03:26

I want to caching some response with symfony\\cache. But I\'ve got some error with my cache and sometime with the symfony default cache.

Configuration :

Deb

2条回答
  •  遥遥无期
    2020-12-22 04:25

    If you happened to use FAT/FAT32 or another file system with severely limited timestamp range, then that warning is to be expected.

    Symfony's FilesystemCommonTrait::write() method calls touch() function with unix timestamp 0 to force expire cached content. Unix timestamp 0 represents 1970-01-01 date. In FAT file system the allowed timestamp range is 1980-01-01 to 2099-12-31, according Wikipedia. So the touch() function fails and a warning is issued.

    The workaround is to modify the FilesystemCommonTrait::write() method, around line 80.

    Find lines:

    if (null !== $expiresAt) {
        touch($this->tmp, $expiresAt);
    }
    

    Insert before those lines:

    if (0 === $expiresAt) {
        $expiresAt = time() - 1;
    }
    

    This should achieve virtually the same result by instantly expiring the cached content, but without using an invalid file system timestamp.

    Alternatively, change the file system type.

提交回复
热议问题