Will a CRON job be suitable for this? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a database with an email address, an interval of how often someone wants an email sent to them (ranges from every 5 minutes to every couple of days) and the time at which an email was last sent. I currently have a PHP script that runs through the database and finds times before the current time and sends them an email and updates the time at which it is scheduled send the new email (using the interval).
Would it be OK to set this script up as a CRON job and run it every say 4 minutes? Or would this create too much overhead? I have 500+ tuples of data that it will need to traverse every 4 minutes.

First off, don't send anyone an email unless they have requested it specifically or your sever will be black listed for spam and no emails will get through.
Second, a cron job is perfect for that kind of job. If the maximum rate is one email every 5 minutes there would be an average of 100 emails every 1 minute cron run (if everyone for some mind boggling reason did decide to have an email that frequently)

Yes, this is a good candidate for a CRON job. No, it's not too much processing overhead to run this every 4 minutes. You should use SQL to query only those rows that may need an email, and running such a query should take about 25 ms.
But from a business perspective, once per day (every 24 hours) or a few times per day should be sufficient & indeed preferable. As the commenter above said.

Related

Cron job for Laravel json api [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I will try to explain what I am trying to achieve. I am writing laravel json api with MySQL. Imagine user creates record inside my database. What I want to do is perform some kind of operation 24 hours after this record is created. It's something like cron job but what will be the the best solution? Should I run cron for example every 5 minutes and check if expired 24 hours for any of the records? Or maybe there is better solution?
You should use the Laravel queue system for this. When you insert a record in the database, you should create a new delayed job. Set the delay to 24 hours and Laravel will execute the job at that moment.
AfterInsertJob::dispatch()->delay(now()->addHours(24));
cron is fine, but (mysql) databases have events, which can be scheduled. In my opinion, this is really down to your personal taste and therefore more or less off-topic here. I mean an update after 24 hours on the entries is one SQL statement which should be rather fast, unless you have millions of entries ;)

Send auto email on delay for each MySQL entry [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I currently have a MySQL database that sends an auto email each time a new record is entered. I need to also send a reminder email to the email address in each row 5 days after it is inserted. What is the best way to do this? Can I use a MySQL trigger or a cron job? I will likely need step by step instructions, if it isn't through PHP. I've done quite a bit of searching but can't find exactly what I'm looking for.
A cron job is what you need. The php file doing the cron needs to query the table for rows where the entry date is equal to 5 days ago. The mysql query is:
SELECT `email` FROM `entries` WHERE date(`entrytimestamp`) = date_sub(curdate(), INVERVAL 5 DAY);
Hopefully this gets you started in the right direction. You'll need to make sure that the php file cannot be called outside of cron, that cron only happens once a day, or maybe keep a separate table logging the emails where you would add a "NOT IN email_log" condition to make sure that you don't double up on emails to someone.

php form to email on scheduled time / date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am going to do a basic form to email script, which is not a problem where you press send and the email goes. but what i want to do is i want to put additional fields in there for date and time and the email will go on that particular date/time. what is the best way to achieve this?
so for example at tuesday 13:30 i would like this script to run to send the email
send-mail.php?mail_id=4
and tuesday 13:45 send-mail.php?mail_id=5 where mail_id changes the mail recipients, content etc.
do i need to run another script every single minute to check in mysql if there is anything to be send? like
select * from mails where datetime = NOW() and if yes do the script? i dont think it is very good option as mysql will run 24/7 .
what are you recommendations
You could have a cron job that runs every 15 minutes and runs a sql statement like:
select * from mails where datetime <= NOW() AND isSent = 0
This would send all emails that are less then or equal to the current time. Make sure you update the record so you know it has been sent.

PHP based games [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am wondering, when you want to make a php based games, that requires the player to wait for something, for example: I paid 100 gold to explore, and every 5 minutes I will receive loot. The exploration will ends in 30 minutes for example. I want to know, which is the best and why. Here are the options:
Keep record of starting time of the exploration command issued, then every time the one specific exploring player open the page, calculate everything and show the result then keep it in the database.
Make a cron job to calculate exploration of EVERY player currently exploring every 5 minutes and update it to database.
Make a cron job every 30 minutes to calculate and update everything for EVERY PLAYER, but also allow SPECIFIC PLAYER to update just like option 1.
option 3 is basically combination of option 1 and 2. Thanks for the help. I am not sure about the performance issue so I need to know from people who already had experience in this.
These are just some personal opinion, might not be the best choice.
2) is more of a general approach for multiplayer game that has player interaction, but it puts constant strain on the server, which seems to be over kill as I seriously doubt your game would have complex interaction between players.
1) is probably the way to go unless your calculation is very complex and take a long time. The possible drawback is that you'll probably have trouble handling lots of simultaneous request to update. But from what you describe I don't think that'll happen.
3)This is hard to comment on because I have no idea if your calculation-time would depends on how much time it has pass since last update. If you calculation is time-indepentdent, then it's a horrible method as you spend time to update data that no one might need AND you are open to traffic spike as well.

PHP Auction Expiry Tracking [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to send e-mails or perform functions on a small, non-real money auction script? This script is a learning exercise for me and I was wondering what the best way would be to process actions when the auction has expired. A cron job every minute seems - to me - a method which can easily be surpassed.
To be honest, this is an ideal situation for a cronjob. Theoretically, you could create cronjobs on the fly...That is edit the crontab with php and create an entry for each auction with their end time to execute a generic script that has some variables passed to it.
A cronjob every minute seems a bit extreme, but if you space it out a bit the idea seems very reasonable.
Alternatives would be for if someone hits the auction page that the script checks to see if the auction is expired and then sends an email and sets a flag in a table column. This overall is a terrible idea (What if no one visits the page for a few days).
Ideally the cronjob is your best friend here. Now you can go with an hourly style cronjob or create a script that generates one time cronjobs on the fly. The best solution though would be a recurring cronjob (per 10 minutes perhaps?) and as it sends out an email for an auction, a flag is set in an column ie email_sent to 1 or something similar so that emails aren't resent erroneously.

Categories