cron是在php中编写基于提醒的应用程序的最佳方式吗?

Suppose I have a database like this.

| task                      |  time                     | 
|---------------------------|---------------------------| 
| Remind me to water plants |  2018-02-18T19:32:10.486Z | 
| English Test              |  2018-10-8T09:30:00.000Z  | 
| Math Test                 |  2018-10-8T10:30:00.000Z  | 

And I want to send a reminder notification to the user at the time it has been requested (or maybe an hour before) by the user and also execute some other block of code at that specific time when reminder notification is triggered.

I am thinking of writing a cron job something like this

* * * * * php /laravel-project/artisan schedule:run >> /dev/null 2>&1

as mentioned in laravel documentation (https://laravel.com/docs/5.6/scheduling).

And inside that script, I will be looping onto current time reminders and reminders within next hour and perform actions.

Is it a good practice? Won't it increase traffic between PHP and database? What if i have lot of reminders within the same hour, looping into that and executing blocks of code foreach reminder will be it a good idea?

Please suggest ideas

Using the task scheduler is the correct way to go about this. If you have a large number of reminders to process then setting them up to execute as queued jobs is the recommended approach. That way the load on the server is minimized and does't bottleneck the system for user traffic.

You'll probably want to create a console command to handle the processing logic and create the jobs. Chunking the jobs will also be helpful, as that will stagger out the number of jobs processed in a given batch.

Long time ago I have the same question for a SMS (Text) message system and I choose use my own cron script schedule at cron . At my PHP script I prevent it from being called by browser, the I add in the follow shell script how many PHP services I want. To keep everything secure, each PHP service needs a small token to run so, you will notice only if you have access to the source code.

#!/bin/sh
#
# (c) 2016 por Marcello Fontolan
#
PATH=$PATH:/sbin:/usr/sbin
export PATH
LOCKFILE=/tmp/${0##*/}.lock

if [ ! -e $LOCKFILE ]
then
        touch $LOCKFILE
        cd ${0%/*}
        php movimentocopia.php token
        php pedidocopia.php token
        rm $LOCKFILE -f
else
        echo lock file detected.
fi
exit

At this moment I handle a different problem. The provider connection and response time slow the amount of Text Message so I create a PID Queued Spool.

Something like this:

function execThis($c, $m) {
    $cmd = "nohup nice -n 10 /usr/bin/php -f execenvio.php {$c} {$m} >> /tmp/execenvio.log 2>&1 & echo $!";
    return intval(shell_exec($cmd));
}

while (count($pid) > NUMTASKS) {
    foreach ($pid as $kpid => $vpid) {
        $processState = NULL;
        exec('ps ' . $vpid, $processState);
        if (count($processState) < 2)
            unset($pid[$kpid]);
    }
}
$pid[] = execThis($vcliente->id, $vmensagem->id);

Well, the code above is part of my current system so you have only to figured out how adapt to your needs.

regards