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. 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. The javascript function makes an ajax call which sends a constantly changing value (a video's seek time for example) as so:
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.
Now, the function that my 'updateDetails' URL is calling a function which basically has a series of file operations. 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. Ok, so now, here's the really really weird part. Attention point 1 gives me all the correct things. 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). Every other variable in that array comes out right. And the value of seek_time in storeMe is correct UNTIL that damn storage line. After that, the last variable becomes 0. So what it looks like to me is that the storage line is CHANGING my variable! 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
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire