Laravel store the time difference into server











up vote
0
down vote

favorite












Ok, so now I'm building a VueJS + Laravel web application. My main function for the app is when it reaches a certain time(startTime), the user will be able to click a button and store the time difference between the time when user pressed the button and the startTime to the database. Note: there will be around 25users submitting at the same time, spamming the record button. Each user can only record once. The one with the shortest difference in time will win the competition.



Currently, I've thought of two ways,



(i) Use javascript Date.now() to get the current time and subtract by the start time and then send the timeDiff from front end to backend. It's fast but Date.now() depends on the client system time, which if the user changes its' system time, they can either draw earlier or later since it doesn't matter as long as the time matches the start time.



(ii) Everything is processed in the backend. A timestamp will be generated on the server every time a user press the record button. It doesn't have the issue (i) has but due to the performance of Laravel, it looks like the server is stalling the request thus making the timestamp not accurate at all.



Any suggestions or advices? I'm still new to all this and these are the 2 methods I can think of right now.



if(auth()->user()->recorded !== 1){ //check if recorded

//create timestamp in epoch
$pressTime = microtime(true)*1000;
$offTimeStart = $user->startTime;
$offTimeEnd = $user->endTime;
$pressedTime = $user->pressTime;//initially 999999999

//prevent user spamming record btn
if($pressTime > $pressedTime){ return something;}

//check if still within the range
if($pressTime >= $offTimeStart && $pressTime < $offTimeEnd){
if($user != null){
$user->update([
'pressTime' => $pressTime,
'recorded' => 1
]);}









share|improve this question
























  • Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
    – Jeff
    Nov 10 at 18:57










  • Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
    – Stephen Lake
    Nov 10 at 19:41












  • I've edited the post and added the code for the function.
    – jiale1029
    Nov 11 at 3:44










  • @snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
    – jiale1029
    Nov 11 at 4:14















up vote
0
down vote

favorite












Ok, so now I'm building a VueJS + Laravel web application. My main function for the app is when it reaches a certain time(startTime), the user will be able to click a button and store the time difference between the time when user pressed the button and the startTime to the database. Note: there will be around 25users submitting at the same time, spamming the record button. Each user can only record once. The one with the shortest difference in time will win the competition.



Currently, I've thought of two ways,



(i) Use javascript Date.now() to get the current time and subtract by the start time and then send the timeDiff from front end to backend. It's fast but Date.now() depends on the client system time, which if the user changes its' system time, they can either draw earlier or later since it doesn't matter as long as the time matches the start time.



(ii) Everything is processed in the backend. A timestamp will be generated on the server every time a user press the record button. It doesn't have the issue (i) has but due to the performance of Laravel, it looks like the server is stalling the request thus making the timestamp not accurate at all.



Any suggestions or advices? I'm still new to all this and these are the 2 methods I can think of right now.



if(auth()->user()->recorded !== 1){ //check if recorded

//create timestamp in epoch
$pressTime = microtime(true)*1000;
$offTimeStart = $user->startTime;
$offTimeEnd = $user->endTime;
$pressedTime = $user->pressTime;//initially 999999999

//prevent user spamming record btn
if($pressTime > $pressedTime){ return something;}

//check if still within the range
if($pressTime >= $offTimeStart && $pressTime < $offTimeEnd){
if($user != null){
$user->update([
'pressTime' => $pressTime,
'recorded' => 1
]);}









share|improve this question
























  • Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
    – Jeff
    Nov 10 at 18:57










  • Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
    – Stephen Lake
    Nov 10 at 19:41












  • I've edited the post and added the code for the function.
    – jiale1029
    Nov 11 at 3:44










  • @snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
    – jiale1029
    Nov 11 at 4:14













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Ok, so now I'm building a VueJS + Laravel web application. My main function for the app is when it reaches a certain time(startTime), the user will be able to click a button and store the time difference between the time when user pressed the button and the startTime to the database. Note: there will be around 25users submitting at the same time, spamming the record button. Each user can only record once. The one with the shortest difference in time will win the competition.



Currently, I've thought of two ways,



(i) Use javascript Date.now() to get the current time and subtract by the start time and then send the timeDiff from front end to backend. It's fast but Date.now() depends on the client system time, which if the user changes its' system time, they can either draw earlier or later since it doesn't matter as long as the time matches the start time.



(ii) Everything is processed in the backend. A timestamp will be generated on the server every time a user press the record button. It doesn't have the issue (i) has but due to the performance of Laravel, it looks like the server is stalling the request thus making the timestamp not accurate at all.



Any suggestions or advices? I'm still new to all this and these are the 2 methods I can think of right now.



if(auth()->user()->recorded !== 1){ //check if recorded

//create timestamp in epoch
$pressTime = microtime(true)*1000;
$offTimeStart = $user->startTime;
$offTimeEnd = $user->endTime;
$pressedTime = $user->pressTime;//initially 999999999

//prevent user spamming record btn
if($pressTime > $pressedTime){ return something;}

//check if still within the range
if($pressTime >= $offTimeStart && $pressTime < $offTimeEnd){
if($user != null){
$user->update([
'pressTime' => $pressTime,
'recorded' => 1
]);}









share|improve this question















Ok, so now I'm building a VueJS + Laravel web application. My main function for the app is when it reaches a certain time(startTime), the user will be able to click a button and store the time difference between the time when user pressed the button and the startTime to the database. Note: there will be around 25users submitting at the same time, spamming the record button. Each user can only record once. The one with the shortest difference in time will win the competition.



Currently, I've thought of two ways,



(i) Use javascript Date.now() to get the current time and subtract by the start time and then send the timeDiff from front end to backend. It's fast but Date.now() depends on the client system time, which if the user changes its' system time, they can either draw earlier or later since it doesn't matter as long as the time matches the start time.



(ii) Everything is processed in the backend. A timestamp will be generated on the server every time a user press the record button. It doesn't have the issue (i) has but due to the performance of Laravel, it looks like the server is stalling the request thus making the timestamp not accurate at all.



Any suggestions or advices? I'm still new to all this and these are the 2 methods I can think of right now.



if(auth()->user()->recorded !== 1){ //check if recorded

//create timestamp in epoch
$pressTime = microtime(true)*1000;
$offTimeStart = $user->startTime;
$offTimeEnd = $user->endTime;
$pressedTime = $user->pressTime;//initially 999999999

//prevent user spamming record btn
if($pressTime > $pressedTime){ return something;}

//check if still within the range
if($pressTime >= $offTimeStart && $pressTime < $offTimeEnd){
if($user != null){
$user->update([
'pressTime' => $pressTime,
'recorded' => 1
]);}






laravel vue.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 3:52

























asked Nov 10 at 18:12









jiale1029

11




11












  • Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
    – Jeff
    Nov 10 at 18:57










  • Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
    – Stephen Lake
    Nov 10 at 19:41












  • I've edited the post and added the code for the function.
    – jiale1029
    Nov 11 at 3:44










  • @snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
    – jiale1029
    Nov 11 at 4:14


















  • Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
    – Jeff
    Nov 10 at 18:57










  • Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
    – Stephen Lake
    Nov 10 at 19:41












  • I've edited the post and added the code for the function.
    – jiale1029
    Nov 11 at 3:44










  • @snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
    – jiale1029
    Nov 11 at 4:14
















Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
– Jeff
Nov 10 at 18:57




Welcome to SO! I don't think you will get much help on this since this site is for code help, and you haven't posted any code.
– Jeff
Nov 10 at 18:57












Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
– Stephen Lake
Nov 10 at 19:41






Obviously backend coordination is the way to go because there are too many concerns of altering data from the frontend - the frontend should never be in charge of data, however the most concerning thing here is your comment on the performance of Laravel, can you give us some context there? It's very abnormal for Laravel to be stalling jobs, something doesn't sound right.
– Stephen Lake
Nov 10 at 19:41














I've edited the post and added the code for the function.
– jiale1029
Nov 11 at 3:44




I've edited the post and added the code for the function.
– jiale1029
Nov 11 at 3:44












@snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
– jiale1029
Nov 11 at 4:14




@snh I'm not sure whether it's my server acting something weird because all my usage went to max when the user pressed the button
– jiale1029
Nov 11 at 4:14

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241972%2flaravel-store-the-time-difference-into-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241972%2flaravel-store-the-time-difference-into-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ