1
I’m developing a system of deadlines and alerts. The user will register a deadline, date and time of the deadline and define if he wants to receive the alert 1, 2 or 3 hours in advance.
How could I perform a function that keeps checking and it’s time to send the email to the user? I didn’t want to make a CRON to run every minute and check if it’s time to send the email.
Is there any way to create an automatic CRON for it to run only when sending the email to the user.
Running only on time involves checking whether it’s already time or not (you can’t get away from it, whether it’s cron or not)... A cron would be the best solution in this case, no problem if it is minute to minute. https://laravel.com/docs/5.6/scheduling
– Miguel
Anyway you should check from time to time. Otherwise how will you know it’s already time ? Use cron
– Pedro Augusto
Leave a Schedule running every minute and check the database to see if it’s time to send an email, it wouldn’t weigh the server?
– Josivan Sousa
You can use the Command
at
(Linux) for the script to be executed at a given time. If I’m not mistaken, you can run Command using shell_exec and it will run only once at the given time. However, I never used it via PHP, only via CLI.– Gabriel Heming
@Gabrielheming this command and as this link itself indicates, this is similar to cron... And no doubt you will have to check from time to time if it is time to run the program. And it is also obsolete as it says on this link.
– Miguel
@Miguel I think we read different things, I researched here, here and here and all the information you have reported now is for windows ([...]but is now deprecated in favor of schtasks.exe[...]). I haven’t located anywhere that’s obsolete (Unix-Like systems) and even if it is processed minute/minute, just like cron, there will be no overhead of running the PHP script, that is, it is less expensive.
– Gabriel Heming
Yes @Gabrielheming, you’re right it was my distraction, I saw windows and assumed it was windows. Of any the check is done, it has to be
– Miguel
Yes @Miguel, but no overhead, because the validation PHP code (if it’s time to execute) will be executed only once. In other words, it will cost less to the server. I am far from my linux server to make an example, when I arrive in case I will (if no one has answered yet). Here is more information about
at
and variants: https://unix.stackexchange.com/questions/97882/why-do-we-need-the-at-command-in-linux– Gabriel Heming
Yes, exact @Gabrielheming, the script is not even called if it’s not time.
– Miguel