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
]);}
laravel vue.js
add a comment |
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
]);}
laravel vue.js
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
add a comment |
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
]);}
laravel vue.js
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
laravel vue.js
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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