Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileCache data can not be shared over web and cli #17365

Closed
gerpayt opened this issue Jun 13, 2019 · 7 comments
Closed

FileCache data can not be shared over web and cli #17365

gerpayt opened this issue Jun 13, 2019 · 7 comments
Labels
expired Information requested was not provided in two weeks. status:need more info type:bug Bug

Comments

@gerpayt
Copy link

gerpayt commented Jun 13, 2019

I cleared all file cache before, then I set a cache via web, wait it until expired, and then I set the same key cache via cli, I got failed.

  • step1: delete runtime/cache/*
  • step2: I run the action below(via web)
    public function actionTestCache()
    {
        $key = "test";
        $cache = Yii::$app->cache;
        $ret = $cache->get($key);
        var_dump($ret);

        $data = 'hello';
        $status = $cache->set($key, $data, 10);
        var_dump($status);

    }

I got bool(false) bool(true)

  • step3: wait 10 seconds
  • step4: run the same action(via cli)
    same code was copied to command dir
    I got the result:
bool(false)
bool(false)

conclusion: cache can not be set!

Additional info

Q A
Yii version 2.0.15
PHP version 7.1.23
Operating system macOS mojave 10.14.3
@gerpayt
Copy link
Author

gerpayt commented Jun 13, 2019

I guess the problem was caused by touch function in php
the function setValue() in FileCache.php

    protected function setValue($key, $value, $duration)
    {
        $this->gc();
        $cacheFile = $this->getCacheFile($key);
        if ($this->directoryLevel > 0) {
            @FileHelper::createDirectory(dirname($cacheFile), $this->dirMode, true);
        }
        if (@file_put_contents($cacheFile, $value, LOCK_EX) !== false) {
            if ($this->fileMode !== null) {
                @chmod($cacheFile, $this->fileMode);
            }
            if ($duration <= 0) {
                $duration = 31536000; // 1 year
            }

            return @touch($cacheFile, $duration + time());
        }

        $error = error_get_last();
        Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__);
        return false;
    }

touch() function always return False when operator is different with the owner of cache file.

@samdark samdark added status:to be verified Needs to be reproduced and validated. type:bug Bug labels Jun 14, 2019
@samdark
Copy link
Member

samdark commented Jun 14, 2019

What would it give you if you'll remove @?

@samdark
Copy link
Member

samdark commented Jun 14, 2019

Also try updating to latest release of the framework.

@samdark samdark added status:need more info and removed status:to be verified Needs to be reproduced and validated. labels Jun 18, 2019
@yiisoft yiisoft deleted a comment from yii-bot Jun 18, 2019
@machour machour added the expired Information requested was not provided in two weeks. label Jul 4, 2019
@yii-bot
Copy link

yii-bot commented Jul 4, 2019

It has been 2 or more weeks with no response on our request for more information.
In order for our issue tracker to be effective, we are closing this issue.

If you want it to be reopened again, feel free to supply us with the requested information.

Thanks!

This is an automated comment, triggered by adding the label expired.

@yii-bot yii-bot closed this as completed Jul 4, 2019
@xcopy
Copy link
Contributor

xcopy commented Dec 8, 2024

Yeah, even more: I've got

   WARNING  Trying to access array offset on null in vendor/yiisoft/yii2/caching/FileCache.php on line 162.

because

$error = error_get_last(); // => null
Yii::warning("Unable to write cache file '{$cacheFile}': {$error['message']}", __METHOD__);

Here is the proposed solution:

$message = "Unable to write cache file '{$cacheFile}'";

if ($error = error_get_last()) {
    $message .= ": {$error['message']}";
}

Yii::warning($message, __METHOD__);

@samdark
Copy link
Member

samdark commented Dec 8, 2024

@xcopy do you have time to do a pull request?

@xcopy
Copy link
Contributor

xcopy commented Dec 8, 2024

Yes, sure.

xcopy added a commit to xcopy/yii2 that referenced this issue Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expired Information requested was not provided in two weeks. status:need more info type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants