简体   繁体   English

存储错误Laravel 5.1

[英]Storage Error Laravel 5.1

So I've been having this annoying bug for quite some time and I've been hesitant to post here since it's not something you can fix unless you understand the entire code, but this is a really odd error that I'm not able to wrap my head around. 所以我一直有这个烦人的bug已经有一段时间了,我一直犹豫要发布在这里,因为除非你理解整个代码,否则你不能修复它,但这是一个非常奇怪的错误,我无法包裹我的头。 I'll try to explain what I'm doing to the best of my ability. 我会尽力解释我正在做的事情。 I just need to brainstorm and maybe think of possible reasons as to why this is happening. 我只需要集思广益,并考虑可能的原因,为什么会发生这种情况。 Any help would be really really appreciated! 任何帮助真的很感激! So, here goes. 所以,这里。

I have a javascript call that's being made every 2 seconds. 我有一个每2秒发出一次javascript调用。 The javascript function makes an ajax call which sends a constantly changing value (a video's seek time for example) as so: javascript函数进行ajax调用,发送一个不断变化的值(例如视频的搜索时间),如下所示:

function startCron()
    {
        window.setInterval(function()
        {
                //Get all the variables, etc. etc.
                $.ajax({
                    type: 'GET',
                    url: 'updateDetails',
                    data: 
                    {
                        'seekTime': upSeekTime      
                    },
                    success: function(updates)
                    {
                        alert(updates);
                    }
                });

            }
        }, 2000);
    }

Now this function works fine! 现在这个功能正常! It get's called every 2 seconds, it sends the correct values and it returns back and executes the success function. 它每2秒调用一次,它发送正确的值并返回并执行成功函数。

Now, the function that my 'updateDetails' URL is calling a function which basically has a series of file operations. 现在,我的'updateDetails'URL正在调用一个函数,该函数基本上具有一系列文件操作。 It involves opening one file, storing, opening a few other files, finally opening one last file, storing in it and returning back what it just stored. 它涉及打开一个文件,存储,打开一些其他文件,最后打开最后一个文件,存储在其中并返回它刚存储的内容。 I know, that sounds pretty confusing and some might think it's inefficient, but hang in with me here. 我知道,这听起来很混乱,有些人可能认为效率低下,但在这里和我在一起。

        //First file get and put process

        $updatedSeekTime = round(Input::get('seekTime'));
        $currentDetails = Storage::get("fileone");
        list($fileID, $fileStatus, $fileSeekTime) = explode(",", $currentDetails, 3);
        $storeMe = array(
                    "user_id" => $user_id,
                    "status" => $fileStatus,
                    "seek_time" => $updatedSeekTime
                    );
        $storeMe = implode(",", $storeMe);
        Storage::disk('local')->put($user_id, $storeMe);



        //Now for the second file retrieving process
        for($i=1;$i<=2;$i++)        //Yes, 1 and 2 are file names.
        {
                $currentDetails = Storage::get($i);
                list($fileID, $fileStatus, $fileSeekTime) = explode(",", $currentDetails, 3);
                $allSeekKebabs[] = $fileSeekTime;
        }

        //Now I find all the minimum value from my array
        $minSeekVal = min($allSeekKebabs);



        //And the final file put process
        $storeMe = array(
                    "user_id" => $user_id,
                    "status" => $fileStatus,
                    "seek_time" => $minSeekVal
                    );
        $storeMe = implode(",", $storeMe);

        //return $storeMe;            //OKAY ATTENTION POINT 1
        Storage::disk('local')->put($user_id, $storeMe);   //PROBLEM POINT
        //return $storeMe;            //OKAY ATTENTION POINT 2

Now. 现在。 If you've made it to this point, a cookie to you because I didn't think most people would read past my code. 如果你已经做到了这一点,给你一个cookie,因为我认为大多数人都不会读过我的代码。 Ok, so now, here's the really really weird part. 好的,现在,这是非常奇怪的部分。 Attention point 1 gives me all the correct things. 注意点1给了我所有正确的东西。 BUT, if I return the SAME variable right after that storage line, like in Attention point 2, the file just stores 0 as the last variable (seek_time according to the last storeMe array). 但是,如果我在该存储行之后立即返回SAME变量,就像在注意点2一样,该文件只存储0作为最后一个变量(seek_time根据最后一个storeMe数组)。 Every other variable in that array comes out right. 该数组中的每个其他变量都是正确的。 And the value of seek_time in storeMe is correct UNTIL that damn storage line. 并且storeMe中的seek_time的值是正确的,直到该死的存储线。 After that, the last variable becomes 0. So what it looks like to me is that the storage line is CHANGING my variable! 之后,最后一个变量变为0.所以我看起来就是存储线正在改变我的变量! Sounds crazy, right? 听起来很疯狂吧? I've been cracking my head on this for so long. 我已经在这方面坚持了很久。

I have checked EVERY possible line before that problem point and everything is ayy-okay. 我已经在问题点之前检查了每条可能的线路,一切都是好的。 But that damn line messes everything up and I just can't figure out why. 但那条该死的线条让一切都搞砸了,我无法弄明白为什么。 My routes file is fine too! 我的路线档也很好!

Any help would be VERY appreciated. 任何帮助都将非常感激。 You can see how frustrated this thing's gotten me. 你可以看到这件事让我感到沮丧。 All I'm asking for is, is there something I'm missing technically. 我要求的是,技术上是否有一些我缺失的东西。 I know that it's near impossible to get a direct answer in this situation, but just any thought, no matter how farfetched, do let me know! 我知道在这种情况下几乎不可能得到直接答案,但只要有任何想法,无论多么牵强,都要让我知道!

Thanks a lot guys :D 非常感谢你们:D

Is $user_id a path that exists on your server ? $ user_id是服务器上存在的路径吗? because it should be: 因为它应该是:

https://laravel.com/api/5.1/Illuminate/Contracts/Filesystem/Filesystem.html#method_put https://laravel.com/api/5.1/Illuminate/Contracts/Filesystem/Filesystem.html#method_put

bool put( string $path, string|resource $contents, string $visibility = null) bool put(string $ path,string | resource $ contents,string $ visibility = null)

Write the contents of a file. 写下文件的内容。

Parameters 参数

string $path string $ path
string|resource $contents string | resource $ contents
string $visibility Return Value string $ visibility返回值

bool 布尔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM