php - Should we put a timer on server or mobile?
I am working on both server side (beginning) and mobile side. There is an interesting thing but I am lack of experience to make a decision. I am appreciated any helps from you guys.
I have to send an email after 50 minutes
1/ If we have a timer for each email on server, then 1000 users, 1000 timers?
2/ If we handle it on mobile, there is a case that everything of the app is killed by OS before sending email.
The question is: server and mobile, which one is better?
Please let me know your solution. Thank you in advanced!
Answer
Solution:
Use a queue
system on the server. Create a queue for sending emails.
When you want to send an email just push it in the queue, with time or DateTime in your case. Then run a Cron Job
to check, process and send the email.
Also, make sure to implement the retry functionality, so that even email sending was failed the Cron will take the job again and try to send for a number of times
.
These Links will Help:
If you are confused about how to setup the Timings of Cron, checkout this website:
Answer
Solution:
This is better to implement the timer on your server. The negative possibility that would happen and block the function if you implement the timer on the device is when the device is on power-off mode or the device couldn't connect to the server to trigger for sending the email.
The server instance
is should long-lived, this is should never go down, and this could be more reliable for your case, as @Harish ST answer, you can take a profit from cron job / cron task.