Check database every minute and then send notification
So I have a .php script where it checks the database for a date/time and if that date and time is within the next 30 min, then it will send them an email notification.
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
...
sendEmailReminder($userId);
I’m running a cron job of this script every minute to make sure the email reminders are being sent out for people who have a meeting within the next 30 min. But I feel like this is using a lot of server resources because I have to run this every minute. What do the “big” sites use to check and send reminders out?
There must be a better way of doing this. Thanks!
php mysql apache email cron
add a comment |
So I have a .php script where it checks the database for a date/time and if that date and time is within the next 30 min, then it will send them an email notification.
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
...
sendEmailReminder($userId);
I’m running a cron job of this script every minute to make sure the email reminders are being sent out for people who have a meeting within the next 30 min. But I feel like this is using a lot of server resources because I have to run this every minute. What do the “big” sites use to check and send reminders out?
There must be a better way of doing this. Thanks!
php mysql apache email cron
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13
add a comment |
So I have a .php script where it checks the database for a date/time and if that date and time is within the next 30 min, then it will send them an email notification.
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
...
sendEmailReminder($userId);
I’m running a cron job of this script every minute to make sure the email reminders are being sent out for people who have a meeting within the next 30 min. But I feel like this is using a lot of server resources because I have to run this every minute. What do the “big” sites use to check and send reminders out?
There must be a better way of doing this. Thanks!
php mysql apache email cron
So I have a .php script where it checks the database for a date/time and if that date and time is within the next 30 min, then it will send them an email notification.
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
...
sendEmailReminder($userId);
I’m running a cron job of this script every minute to make sure the email reminders are being sent out for people who have a meeting within the next 30 min. But I feel like this is using a lot of server resources because I have to run this every minute. What do the “big” sites use to check and send reminders out?
There must be a better way of doing this. Thanks!
php mysql apache email cron
php mysql apache email cron
edited Nov 20 at 22:08
Funk Forty Niner
80.5k1247100
80.5k1247100
asked Nov 20 at 21:57
pixie123
186514
186514
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13
add a comment |
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13
add a comment |
2 Answers
2
active
oldest
votes
if you have a large amount of data you have to use one of the queueing systems like
beanstalkd
https://beanstalkd.github.io/
https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf
redis
https://redis.io/commands/rpoplpush
once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
add a comment |
The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.
But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).
Then if true, execute this script
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
ELSE, do nothing.
Execute this script each minute with CRON.
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53402214%2fcheck-database-every-minute-and-then-send-notification%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
if you have a large amount of data you have to use one of the queueing systems like
beanstalkd
https://beanstalkd.github.io/
https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf
redis
https://redis.io/commands/rpoplpush
once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
add a comment |
if you have a large amount of data you have to use one of the queueing systems like
beanstalkd
https://beanstalkd.github.io/
https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf
redis
https://redis.io/commands/rpoplpush
once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
add a comment |
if you have a large amount of data you have to use one of the queueing systems like
beanstalkd
https://beanstalkd.github.io/
https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf
redis
https://redis.io/commands/rpoplpush
once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs
if you have a large amount of data you have to use one of the queueing systems like
beanstalkd
https://beanstalkd.github.io/
https://media.readthedocs.org/pdf/php-beanstalk/latest/php-beanstalk.pdf
redis
https://redis.io/commands/rpoplpush
once you get a new meeting insert a new job into the queue with a delay to the time that you want to send the reminder and keep a consumer listening to the queue for ready to pick jobs
answered Nov 20 at 22:19
Baha'a Odeh
3681415
3681415
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
add a comment |
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
This is what I needed! What do the "big" sites like facebook or google use? What's the best solution of easy scalability?
– pixie123
Nov 20 at 22:31
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
I think the best solution for this is redis as it supports clustering if you want to use beanstalkd you can use multiple tube and multiple server
– Baha'a Odeh
Nov 25 at 12:00
add a comment |
The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.
But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).
Then if true, execute this script
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
ELSE, do nothing.
Execute this script each minute with CRON.
add a comment |
The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.
But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).
Then if true, execute this script
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
ELSE, do nothing.
Execute this script each minute with CRON.
add a comment |
The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.
But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).
Then if true, execute this script
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
ELSE, do nothing.
Execute this script each minute with CRON.
The best way would be to create an PHP file with your SQL query like what you have now, compare the date_and_time you have in table and compare with current date_and_time using IF/ELSE.
But before, you should SELECT ALL date_and_time from this table to compare with the current date and time +30 minutes (because if i understand, it should be sent 30 min before).
Then if true, execute this script
$stmt = $dbh->prepare(“SELECT user_id FROM meetings WHERE date_and_time = :date_and_time”);
ELSE, do nothing.
Execute this script each minute with CRON.
answered Nov 20 at 22:29
Tonio
14
14
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53402214%2fcheck-database-every-minute-and-then-send-notification%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
Why not try setting the cron to say 30 - 15 mins. instead? TBH, I don't know how the big companies do it, but they most likely have some heavy duty servers working 24/7 and have the resources to do so.
– Funk Forty Niner
Nov 20 at 22:06
why to run this script every minute if you want to send to the next 30 min? select all the next 30 mins
– Baha'a Odeh
Nov 20 at 22:06
Before you start working on optimizing the process. Did you check if a. Your select statement b. The send email logic/code is consuming the time/resources of your server? Once you know which of the two is taking more time/resources, we can try to improve it.
– N0000B
Nov 20 at 22:13